/*============================================================================*/

* Do: Tables and Figures 

/*============================================================================*/

* ==============================================================================
* SECTION: DIRECTORIES
* ==============================================================================

if 		"`c(username)'" == "INSERT YOUR USERNAME HERE" {
			global DIR "INSERT YOUR PATH HERE"					
		}

cd "$DIR"

global RAW		"$DIR"
global CLEAN	"$DIR"
global OUT 		"$DIR"

global TEX 		"$DIR"
global LOG 		"$DIR"
global FIG 		"$DIR"
global TEMP 	"$DIR"


* ==============================================================================
* SECTION: OPTIONS
* ==============================================================================

clear all
set trace off
set more off
set mem 200m
set maxvar 30000

capture log close
log using "$LOG/All_Analysis_Jun2023_tex.log", replace

** Install packages needed
 * ssc install texdoc
 * ssc install coefplot
 * ssc install rwolf
* ==============================================================================
* TABLE 1: TAKE-UP AND USAGE
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

*------------------------ SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5 svar1-svar3

local k = 0

/*
NOTE: THE ORIGINAL CODE SHOULD HAVE THE FOLLOWING START OF THE LOOP:

"foreach y of varlist EL_takeupBM ADamount_ihs ADbalance_ihs EL_saving_ihs {"	

WE HAVE CHANGED IT TO ALLOW THE CODE TO RUN SMOOTHLY, SINCE THE VARIABLES ADamount_ihs ADbalance_ihs ARE NOT PUBLICLY AVAILABLE DUE TO CONFIDENCIALITY CONCERNS

*/

foreach y of varlist EL_takeupBM EL_saving_ihs {
	
	local k = `k' + 1
	local outcome_`k' :var label `y'
	
	* MODEL
	reg `y' high_private high_public low_public `controls', cl(agn_cl) 

	* MAIN ESTIMATES
	local v = 0
	foreach t in "high_private" "high_public-low_public" "high_public-low_public-high_private" {
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b' : di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s' : di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* REGRESSION COEFFICIENTS
	foreach t in high_private high_public low_public {
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b' : di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s' : di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* OBSERVATIONS
	local C`k'R13:  di e(N)

	* R2
	local C`k'R14:   di %12.3fc e(r2)

	* MEAN DEP VARIABLE
	sum `y' 
	local C`k'R15:  di %12.3fc r(mean)

	* MEAN DEP VARIABLE FOR LOW PRIVATE
	sum `y' if low_private == 1
	local C`k'R16:  di %12.3fc r(mean)

	* T-TEST HIGH PRIVATE - HIGH PUBLIC
	test high_private = high_public 
	local C`k'R17:  di %12.3fc r(p)

	* T-TEST HIGH PRIVATE - LOW PUBLIC
	test high_private = low_public 
	local C`k'R18:  di %12.3fc r(p)

	* FORMAT SE ()
	foreach j of numlist 2 4 6 8 10 12 {
		local C`k'R`j': di trim("`C`k'R`j''")
		local C`k'R`j'="(`C`k'R`j'')"
	}
			
	* ADD STARS IF CORRESPONDS
	foreach j of numlist 1 3 5 7 9 11 {
		if `pv`k'R`j'' <= 0.10 & `pv`k'R`j'' > 0.05 {
			local C`k'R`j' = "$`C`k'R`j''^{*}$"
		}
		else if `pv`k'R`j'' <= 0.05 & `pv`k'R`j'' > 0.01 {
			local C`k'R`j' = "$`C`k'R`j''^{**}$"
		}
		else if `pv`k'R`j'' <= 0.01 { 
			local C`k'R`j' = "$`C`k'R`j''^{***}$"
		}
	}

}

* ROW TITLES
local lbl_1  	"(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 	""	
local lbl_3  	"(High - Low) $\ensuremath{\times}$ Public"
local lbl_4  	"" 
local lbl_5  	"(High - Low) $\ensuremath{\times}$ (Public - Private)"  
local lbl_6  	""	
local lbl_7  	"High $\ensuremath{\times}$ Private"	
local lbl_8  	""		
local lbl_9  	"High $\ensuremath{\times}$ Public"
local lbl_10 	""
local lbl_11 	"Low $\ensuremath{\times}$ Public"	
local lbl_12 	""
local lbl_13 	"Observations"	
local lbl_14 	"R-squared"	
local lbl_15 	"Mean Dep. Var."
local lbl_16 	"Mean Dep. Var. for Low $\ensuremath{\times}$ Private"
local lbl_17 	"p-value High $\ensuremath{\times}$ Private - High $\ensuremath{\times}$ Public"	
local lbl_18 	"p-value High $\ensuremath{\times}$ Private - Low $\ensuremath{\times}$ Public"		

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/Table1.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3) & (4) \\\\
tex  \\ [-1.5ex]
tex  & `outcome_1'  & `outcome_2' & `outcome_3' & `outcome_4' \\\\
tex  \hline \\ 
forvalue t = 1/6 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t'' \\
}
tex  \hdashline \\ [-1.5ex]
tex \multicolumn{4}{l}{\underline{Regression Coefficients}} \\\\
forvalue t = 7/12 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t'' \\
}
tex  \\
forvalue t = 13/18 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t''  \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE 2: AGENT EFFORT
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5 svar1-svar3

** Label for Tables
label variable EL_effort_agent_talk 	"Number of \\ Times \\ Products are \\ Advertised"
label variable EL_heard_agn 			"Learned \\ about \\ Products \\ from Agent"
label variable EL_pcaEffort 			"Agent Effort \\ (PC)"
label variable EL_offer_prod 			"Products \\ Offered \\ by Agent"
label variable EL_agn_convince 			"Agent \\ Pro-Actively \\ Promoted \\ Products"
label variable EL_pcaStyle 				"Agent Sales \\ Strategy \\ (PC)"

local k = 0

foreach y of varlist EL_effort_agent_talk EL_heard_agn EL_pcaEffort EL_offer_prod EL_agn_convince EL_pcaStyle {
	
	local k = `k' + 1
	local outcome_`k' : var label `y'
	
	* MODEL
	reg `y' high_private high_public low_public   `controls',  cl(agn_cl) 

	* MAIN ESTIMATES
	local v = 0
	
	foreach t in "high_private" "high_public-low_public" "high_public-low_public-high_private" {
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b':  di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s':  di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* REGRESSION COEFFICIENTS
	foreach t in high_private high_public low_public {
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b':  di %12.3fc _b[`t']
		/*se*/ 		local C`k'R`s':  di %12.3fc _se[`t']
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(_b[`t']/_se[`t'])))
	}

	* OBSERVATIONS
	local C`k'R13:	di e(N)

	* R2
	local C`k'R14:   di %12.3fc e(r2)

	* MEAN DEP VARIABLE
	sum `y' 
	local C`k'R15:  di %12.3fc r(mean)

	* MEAN DEP VARIABLE FOR LOW PRIVATE
	sum `y' if low_private == 1
	local C`k'R16:  di %12.3fc r(mean)

	* T-TEST HIGH PRIVATE - HIGH PUBLIC
	test high_private = high_public 
	local C`k'R17:  di %12.3fc r(p)

	* T-TEST HIGH PRIVATE - LOW PUBLIC
	test high_private = low_public 
	local C`k'R18:  di %12.3fc r(p)

	* FORMAT SE ()
	foreach j of numlist 2 4 6 8 10 12 {
		local C`k'R`j': di trim("`C`k'R`j''")
		local C`k'R`j' = "(`C`k'R`j'')"
	}
			
	* ADD STARS IF CORRESPONDS
	foreach j of numlist 1 3 5 7 9 11 {
		if `pv`k'R`j'' <= 0.10 & `pv`k'R`j'' > 0.05 {
			local C`k'R`j' = "$`C`k'R`j''^{*}$"
		}
		else if `pv`k'R`j'' <= 0.05 & `pv`k'R`j'' > 0.01 {
			local C`k'R`j' = "$`C`k'R`j''^{**}$"
		}
		else if `pv`k'R`j'' <= 0.01 { 
			local C`k'R`j' = "$`C`k'R`j''^{***}$"
		}
	}

}

* ROW TITLES
local lbl_1 	"(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 	""	
local lbl_3 	"(High - Low) $\ensuremath{\times}$ Public"
local lbl_4 	"" 
local lbl_5 	"(High - Low) $\ensuremath{\times}$ (Public - Private)"  
local lbl_6 	""	
local lbl_7 	"High $\ensuremath{\times}$ Private"	
local lbl_8 	""		
local lbl_9 	"High $\ensuremath{\times}$ Public"
local lbl_10 	""
local lbl_11 	"Low $\ensuremath{\times}$ Public"	
local lbl_12 	""
local lbl_13 	"Observations"	
local lbl_14 	"R-squared"	
local lbl_15 	"Mean Dep. Var."
local lbl_16 	"Mean Dep. Var. for Low $\ensuremath{\times}$ Private"
local lbl_17 	"p-value High $\ensuremath{\times}$ Private - High $\ensuremath{\times}$ Public"	
local lbl_18 	"p-value High $\ensuremath{\times}$ Private - Low $\ensuremath{\times}$ Public"		

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/Table2.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3) & & (4) & (5) & (6)   \\\\
tex  &  \multicolumn{3}{c}{Agent Effort} &  & \multicolumn{3}{c}{Agent Sales Strategy}  \\
tex   \cline{2-4} \cline{6-8}
tex  \\ [-1.5ex]
tex   & \makecell{`outcome_1'} & \makecell{`outcome_2'} & \makecell{`outcome_3'} & & \makecell{`outcome_4'} & \makecell{`outcome_5'}  & \makecell{`outcome_6'}  \\\\
tex  \hline \\ 
forvalue t = 1/6 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & & `C4R`t'' & `C5R`t''  & `C6R`t''     \\
}
tex  \hdashline \\ [-1.5ex]
tex \multicolumn{2}{l}{\underline{Regression Coefficients}} \\\\
forvalue t = 7/12 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t'' & & `C4R`t'' & `C5R`t''  & `C6R`t''    \\
}
tex  \\
forvalue t = 13/18 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t'' & & `C4R`t'' & `C5R`t''  & `C6R`t''    \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE 3: PERCEPTIONS OF POTENTIAL CLIENTS
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5 svar1-svar3

* LABEL FOR TABLES
label variable EL_agn_earning 	"Perceived \\ Agent \\ Earnings"
label variable EL_pcaProduct 	"Trust in \\ Product \\ (PC)"
label variable EL_pcaBank 		"Trust in \\ Bank \\ (PC)"
label variable EL_pcaAgent 		"Trust in \\ Agent \\ (PC)"
label variable EL_pcaAll 		"Trust All \\ (PC)"

local k = 0

foreach y of varlist EL_agn_earning EL_pcaProduct EL_pcaBank EL_pcaAgent EL_pcaAll {

	local k = `k' + 1
	local outcome_`k' : var label `y'
	
	* MODEL
	reg `y' high_private high_public low_public `controls',  cl(agn_cl) 

	* MAIN ESTIMATES
	local v = 0
	foreach t in "high_private" "high_public-low_public" "high_public-low_public-high_private" {	
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b' :  di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s' :  di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b':  di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* REGRESSION COEFFICIENTS
	foreach t in high_private high_public low_public {
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*B*/    	local C`k'R`b':  di %12.3fc _b[`t']
		/*se*/ 		local C`k'R`s':  di %12.3fc _se[`t']
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(_b[`t']/_se[`t'])))
	}

	* OBSERVATIONS
	local C`k'R13:  di e(N)

	* R2
	local C`k'R14:   di %12.3fc e(r2)

	* MEAN DEP VARIABLE
	sum `y' 
	local C`k'R15:  di %12.3fc r(mean)

	* MEAN DEP VARIABLE FOR LOW PRIVATE
	sum `y' if low_private == 1
	local C`k'R16:  di %12.3fc r(mean)

	* T-TEST HIGH PRIVATE - HIGH PUBLIC
	test high_private = high_public 
	local C`k'R17:  di %12.3fc r(p)

	* T-TEST HIGH PRIVATE - LOW PUBLIC
	test high_private = low_public 
	local C`k'R18:  di %12.3fc r(p)

	* FORMAT SE ()
	foreach j of numlist 2 4 6 8 10 12 {
		local C`k'R`j': di trim("`C`k'R`j''")
		local C`k'R`j' = "(`C`k'R`j'')"
	}
			
	* ADD STARS IF CORRESPONDS:	
	foreach j of numlist 1 3 5 7 9 11 {
		if `pv`k'R`j'' <= 0.10 & `pv`k'R`j'' > 0.05 {
			local C`k'R`j'="$`C`k'R`j''^{*}$"
		}
		else if `pv`k'R`j'' <= 0.05 & `pv`k'R`j'' > 0.01 {
			local C`k'R`j'="$`C`k'R`j''^{**}$"
		}
		else if `pv`k'R`j'' <= 0.01 { 
			local C`k'R`j' = "$`C`k'R`j''^{***}$"
		}
	}
}

* ROW TITLES
local lbl_1 	"(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 	""	
local lbl_3 	"(High - Low) $\ensuremath{\times}$ Public"
local lbl_4 	"" 
local lbl_5 	"(High - Low) $\ensuremath{\times}$ (Public - Private)"  
local lbl_6 	""	
local lbl_7 	"High $\ensuremath{\times}$ Private"	
local lbl_8 	""		
local lbl_9 	"High $\ensuremath{\times}$ Public"
local lbl_10 	""
local lbl_11 	"Low $\ensuremath{\times}$ Public"	
local lbl_12 	""
local lbl_13 	"Observations"	
local lbl_14 	"R-squared"	
local lbl_15 	"Mean Dep. Var."
local lbl_16 	"Mean Dep. Var. for Low $\ensuremath{\times}$ Private"
local lbl_17 	"p-value High $\ensuremath{\times}$ Private - High $\ensuremath{\times}$ Public"	
local lbl_18 	"p-value High $\ensuremath{\times}$ Private - Low $\ensuremath{\times}$ Public"		

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/Table3.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3) & (4) & (5)   \\\\
tex  \\ [-1.5ex]
tex   & \makecell{`outcome_1'} & \makecell{`outcome_2'} & \makecell{`outcome_3'} &  \makecell{`outcome_4'} & \makecell{`outcome_5'}   \\\\
tex  \hline \\ 
forvalue t = 1/6 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t'' & `C4R`t'' & `C5R`t''  \\
}
tex  \hdashline \\ [-1.5ex]
tex \multicolumn{2}{l}{\underline{Regression Coefficients}} \\\\
forvalue t = 7/12 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t'' & `C4R`t'' & `C5R`t'' \\
}
tex  \\
forvalue t = 13/18 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t'' & `C4R`t'' & `C5R`t'' \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE 4: LONG-TERM EFFECTS ON TAKE-UP AND USAGE (RE-SCALED)
* ==============================================================================

*** NOTE: THIS TABLE USES ADMINISTRATIVE DATA THAT IS NOT PUBLICLY AVAILABLE ***
*** WE COMMENT OUT THIS SECTION OF THE CODE TO ALLOW IT TO RUN SMOOTHLY ****

/*
* MERGE TO FINAL DATASET
use "$OUT/longterm_agentlevel_final.dta", clear

gen TU_rate = med_client/BLnbHH
	replace TU_rate = 0 if TU_rate == .
	label var TU_rate "Take-Up Rate"

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5  svar1-svar3

local k = 0

foreach y of varlist TU_rate med_freq med_freq_cl asinh_med_balance asinh_med_bal_cl asinh_med_sv asinh_med_sv_cl {	

	local label_`y' :var label `y'

	generate NEW_`y' = `y'/(frac_HHentrep + 0.3*(1-frac_HHentrep))
		label var NEW_`y' "`label_`y''"

	local k = `k' + 1
	
	local outcome_`k' :var label NEW_`y'
	
		replace NEW_`y' = 0 if NEW_`y' == .
	
	* MODEL
	reg NEW_`y' high_private high_public low_public   `controls',  cl(agn_cl) 

	* MAIN ESTIMATES
	local v=0
	foreach t in "high_private" "high_public-low_public" "high_public-low_public-high_private" {
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b':  di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s':  di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* REGRESSION COEFFICIENTS
	foreach t in high_private high_public low_public {
		local v = `v' + 1
		local b = 2*`v' - 1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b':  di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s':  di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* OBSERVATIONS
	local C`k'R13:  di e(N)

	* R2
	local C`k'R14:  di %12.3fc e(r2)

	* MEAN DEP VARIABLE
	sum NEW_`y' 
	local C`k'R15:  di %12.3fc r(mean)

	* MEAN DEP VARIABLE FOR LOW PRIVATE
	sum NEW_`y' if low_private==1
	local C`k'R16:  di %12.3fc r(mean)

	* T-TEST HIGH PRIVATE - HIGH PUBLIC
	test high_private = high_public 
	local C`k'R17:  di %12.3fc r(p)

	* T-TEST HIGH PRIVATE - LOW PUBLIC
	test high_private = low_public 
	local C`k'R18:  di %12.3fc r(p)

	* FORMAT SE ()
	foreach j of numlist 2 4 6 8 10 12 {
		local C`k'R`j': di trim("`C`k'R`j''")
		local C`k'R`j' = "(`C`k'R`j'')"
	}
			
	* ADD STARS IF CORRESPONDS
	foreach j of numlist 1 3 5 7 9 11 {
		if `pv`k'R`j'' <= 0.10 & `pv`k'R`j'' > 0.05 {
		local C`k'R`j' = "$`C`k'R`j''^{*}$"
		}
		else if `pv`k'R`j'' <= 0.05 & `pv`k'R`j'' > 0.01 {
		local C`k'R`j'="$`C`k'R`j''^{**}$"
		}
		else if `pv`k'R`j'' <= 0.01 { 
		local C`k'R`j'="$`C`k'R`j''^{***}$"
		}
	}

}

*------------------------ ROW TITLES
local lbl_1 "(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 ""	
local lbl_3 "(High - Low) $\ensuremath{\times}$ Public"
local lbl_4 "" 
local lbl_5 "(High - Low) $\ensuremath{\times}$ (Public - Private)"  
local lbl_6 ""	
local lbl_7 "High $\ensuremath{\times}$ Private"	
local lbl_8 ""		
local lbl_9 "High $\ensuremath{\times}$ Public"
local lbl_10 ""
local lbl_11 "Low $\ensuremath{\times}$ Public"	
local lbl_12 ""
local lbl_13 "Observations"	
local lbl_14 "R-squared"	
local lbl_15 "Mean Dep. Var."
local lbl_16 "Mean Dep. Var. for Low $\ensuremath{\times}$ Private"
local lbl_17 "p-value High $\ensuremath{\times}$ Private - High $\ensuremath{\times}$ Public"	
local lbl_18 "p-value High $\ensuremath{\times}$ Private - Low $\ensuremath{\times}$ Public"		

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/Table4.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3) & (4) \\\\
tex  \\ [-1.5ex]
tex  & `outcome_1' & `outcome_2' & `outcome_3' & `outcome_4'  \\\\
tex  \hline \\ 
forvalue t = 1/6 {
tex `lbl_`t'' & `C1R`t'' & `C2R`t'' & `C3R`t''  & `C4R`t'' \\
}
tex  \hdashline \\ [-1.5ex]
tex \multicolumn{4}{l}{\underline{Regression Coefficients}} \\\\
forvalue t = 7/12 {
tex `lbl_`t'' & `C1R`t'' & `C2R`t'' & `C3R`t''  & `C4R`t'' \\
}
tex  \\
forvalue t = 13/18 {
tex `lbl_`t'' & `C1R`t'' & `C2R`t'' & `C3R`t''  & `C4R`t'' \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*
*/

* ==============================================================================
* FIGURE A1: EVOLUTION OF TAKE-UP OF MOBILE MONEY PRODUCTS AROUND THE WORLD
* ==============================================================================

use "$OUT/GlobalFindex - mobile money.dta", clear

sort year
replace mobile_account = mobile_account*100


twoway (scatter mobile_account year if country == "World", msize(small) msymbol(s) mcolor(black) lw(vthin) connect(direct) lcolor(black) lp(dash)) ///
	   (scatter mobile_account year if country== "Developing", msize(small) msymbol(o) mcolor(black) lw(vthin) connect(direct) lcolor(black) lp(solid)) ///
	   (scatter mobile_account year if country== "East Asia & Pacific (excluding high income)", msize(small) msymbol(x) mcolor(black) lw(vthin) connect(direct) lcolor(black) lp(dot)) ///
	   (scatter mobile_account year if country == "Indonesia", msize(small) msymbol(d) mcolor(black) lw(vthin) connect(direct) lcolor(black) lp(longdash)), ///
	   xlabel(2014 2017 2021, labsize(small)) ylabel(0(2)14, labsize(small) angle(horizontal)) ///
	   ytitle("%", size(small) m(small) orientation(horizontal)) ///
	   xtitle("") ///
	   legend(on cols(1) size(small) bm(medium) label(1 "All countries") label(2 "Low & Middle Income Countries") ///
	   		label(3 "Low & Middle Income Countries in East Asia & Pacific") label(4 "Indonesia")) ///
	   graphregion(color(white)) bgcolor(white) scheme(s1color)

graph export "$FIG/FigureA1.png", replace
 

* ==============================================================================
* FIGURE A3: TAKE-UP OF THE BANK’S BRANCHLESS BANKING PRODUCTS
* FIGURE A4: AGENT EFFORT
* FIGURE A6: TRUST IN PRODUCT, AGENT, AND THE BANK
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

gen information = .
gen incentives = .
replace information		= 1 if public 	== 1
replace information 	= 2 if private 	== 1
replace incentives  	= 1 if high 	== 1
replace incentives  	= 2 if low 		== 1

foreach x of varlist EL_takeupBM EL_effort_agent_talk EL_pcaAll {

	if "`x'" == "EL_takeupBM" {
		local name = "A3"
	}
	if "`x'" == "EL_effort_agent_talk" {
		local name = "A4"
	}
	if "`x'" == "EL_pcaAll" {
		local name = "A6"
	}

	local axisY : var label `x'

	ttest `x' if private == 1, by(incentives)
	local diff1 = r(mu_1) - r(mu_2)
	local se1 = r(se)
	local pv1: di %6.3fc r(p)

	ttest `x' if public == 1, by(incentives)
	local diff2 = r(mu_1) - r(mu_2)
	local se2 = r(se)
	local pv2: di %6.3fc r(p)

	ttest `x' if high == 1, by(information)
	local pv3: di %6.3fc r(p)

	ttest `x' if low == 1, by(information)
	local pv4: di %6.3fc r(p)

	local pv5: di %6.3fc 2*(1-normal(abs((`diff1'-`diff2')/sqrt(`se1'^2+`se2'^2))))

	preserve

		collapse (mean) mean_`x' = `x' (sd) sd_`x' = `x' (count) n = `x', by(information incentives)
		generate h`x' = mean_`x' + invttail(n-1,0.025)*(sd_`x' / sqrt(n))
		generate l`x' = mean_`x' - invttail(n-1,0.025)*(sd_`x' / sqrt(n))

		*------------------------ FORMAT
		* AXIS
		if "`x'" == "EL_takeupBM" {
			local vmin_axis = 0
			local vmax_axis = 0.05
			foreach i in 1 2 3 {
				local k = `i' - 1
				local v_axis`i' = `vmax_axis' - `k'*0.004
				local aux_v`i' = `v_axis`i''- 0.001
			}
		}
		if "`x'" == "EL_effort_agent_talk" {
			local vmin_axis = 0
			local vmax_axis = 0.54
			foreach i in 1 2 3 {
				local k = `i' - 1
				local v_axis`i' = `vmax_axis' - `k'*0.035
				local aux_v`i' = `v_axis`i'' - 0.01
			}
		}
		if "`x'" == "EL_pcaAll" {
			local vmin_axis = 0.56
			local vmax_axis = 0.63
			foreach i in 1 2 3 {
				local k = `i' - 1
				local v_axis`i' = `vmax_axis' - `k'*0.007
				local aux_v`i' = `v_axis`i'' - 0.0017
			}
		}

		* NUMBER OF TICKS 5/6
		local pr_axis: di %6.2fc (`vmax_axis'-(`vmin_axis'))/5

		*------------------------ FIGURE
		generate infinc = incentives    if information == 2 // private first
		replace  infinc = incentives+3  if information == 1 // public second
		
		sort infinc
		
		twoway (bar mean_`x' infinc if incentives == 1,  lcolor(black) fcolor(erose)) ///
		       (bar mean_`x' infinc if incentives == 2,  lcolor(black) fcolor(gs14)) ///
		       (rcap h`x' l`x' infinc), xlabel( 1.5 "Private" 4.5 "Public") ///
		        legend( order(1 "High Incentives" 2 "Low Incentives")) ///		
		       ytitle(`axisY') xtitle("") ylabel(`vmin_axis'(`pr_axis')`vmax_axis') 
			   
		gr_edit style.editstyle boxstyle(shadestyle(color(white))) editcopy
		gr_edit style.editstyle boxstyle(linestyle(color(white))) editcopy

		* P-VALUES
		local k = 0
		foreach y in 1.2 4.2 2.2 3.2 {
			local k = `k'+1
			if `k' == 1 | `k' == 2 {
				local axis`k' = `v_axis1'
			}
			if `k' == 3 | `k' == 4 {
				local j = `k' - 1
				local axis`k' = `v_axis`j''
			}
			gr_edit plotregion1.AddTextBox added_text editor `axis`k'' `y'
			gr_edit plotregion1.added_text[`k'].text.Arrpush p=`pv`k''
		}

		* FIRST LINE
		foreach xa of numlist 1 1.82 4 4.82 {
			local x2 = `xa' + 0.18
			if `xa' == 1 | `xa' == 4 {
				local xv = `xa'
			}
			else {
				local xv = `x2'
			}
			gr_edit plotregion1.AddLine added_lines editor `xa' `v_axis1' `x2' `v_axis1'
			gr_edit plotregion1.AddLine added_lines editor `xv' `v_axis1' `xv' `aux_v1'
		}

		* SECOND LINE
		foreach xa of numlist 1 2.82 {
			local x2 = `xa' + 1.18
			if `xa' == 1 {
				local xv = `xa'
			}
			else {
				local xv = `x2'
			}
			gr_edit plotregion1.AddLine added_lines editor `xa' `v_axis2' `x2' `v_axis2'
			gr_edit plotregion1.AddLine added_lines editor `xv' `v_axis2' `xv' `aux_v2'
		}

		* THIRD LINE
		foreach xa of numlist 2 3.82 {
			local x2 = `xa' + 1.18
			if `xa' == 2 {
				local xv = `xa'
			}
			else {
				local xv = `x2'
			}
			gr_edit plotregion1.AddLine added_lines editor `xa' `v_axis3' `x2' `v_axis3'
			gr_edit plotregion1.AddLine added_lines editor `xv' `v_axis3' `xv' `aux_v3'
		}

		graph export "$FIG/Figure`name'.png", replace

	restore
}

* ==============================================================================
* FIGURE A5: CORRELATION OF TAKE-UP AND TRANSACTION AMOUNT (IHS) WITH AGENT 
*			 EFFORT AND PERCEPTIONS OF POTENTIAL CLIENTS
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5 svar1-svar3

* ALL PREDICTORS

/*
NOTE: THE ORIGINAL CODE SHOULD HAVE THE FOLLOWING START OF THE LOOP:

"foreach y of varlist EL_takeupBM ADamount_ihs {"	

WE HAVE CHANGED IT TO ALLOW THE CODE TO RUN SMOOTHLY, SINCE THE VARIABLE ADamount_ihs IS NOT PUBLICLY AVAILABLE DUE TO CONFIDENCIALITY CONCERNS

*/

foreach y of varlist EL_takeupBM {
	
	local k = 0

	foreach x of varlist  EL_effort_agent_talk EL_heard_agn EL_pcaEffort EL_offer_prod EL_agn_convince EL_pcaStyle ///
	EL_reliable_product  EL_fees_BM  EL_money_safe  EL_safe_product EL_pcaProduct ///
	EL_confidence_BM  EL_trust_banks_village EL_confidence_state_banks EL_pcaBank ///
	EL_trust_agent EL_competent_agent EL_altruism_agent EL_wallet_agent EL_pcaAgent EL_pcaAll {
	
		local k = `k' + 1
		reg `y' `x' `controls',  cl(agn_cl) 
		estimates store A_`k'	
	
	}


	* Agent Effort and Agent Sales Strategy
	coefplot (A_1 A_2 A_3, asequation(Agent Effort) \ ///
			A_4 A_5 A_6, asequation(Agent Sales Strategy)), /// 
		keep(EL_effort_agent_talk EL_heard_agn EL_pcaEffort EL_offer_prod EL_agn_convince EL_pcaStyle) ///
		graphregion(color(white)) xline(0)
	graph export "$FIG/`y'_supply.png", replace

	* Client Perceptions (All, Agent, Bank, Product)
	coefplot (A_7 A_8 A_9 A_10 A_11, asequation(Product) \ ///
			A_12 A_13 A_14 A_15, asequation(Bank) \ ///
			A_16 A_17 A_18 A_19 A_20, asequation(Agent) \ ///		 
			A_21, asequation(All)), /// 
		keep(EL_reliable_product  EL_fees_BM  EL_money_safe  EL_safe_product EL_pcaProduct ///
			 EL_confidence_BM  EL_trust_banks_village EL_confidence_state_banks EL_pcaBank ///
			 EL_trust_agent EL_competent_agent EL_altruism_agent EL_wallet_agent EL_pcaAgent EL_pcaAll) ///
		graphregion(color(white)) xline(0) 
	graph export "$FIG/`y'_demand.png", replace

}

* ==============================================================================
* FIGURE A7: TAKE-UP OF THE BANK’S BRANCHLESS BANKING PRODUCTS - LONG TERM 
*			 EFFECTS
* ==============================================================================

*** NOTE: THIS FIGURE USES ADMINISTRATIVE DATA THAT IS NOT PUBLICLY AVAILABLE ***
*** WE COMMENT OUT THIS SECTION OF THE CODE TO ALLOW IT TO RUN SMOOTHLY ****

/*
use "$OUT/longterm_agentlevel_final.dta", clear

gen TU_rate = avg_client/BLnbHH
	label var TU_rate "Take-Up Rate"

replace TU_rate = 0 if TU_rate == .

*------------------------ COMPUTE THE SCALED DOWN NUMBER OF PEOPLE WHO TOOK UP
generate	TUREnt_1	= TU_rate/(frac_HHentrep + 0*(1-frac_HHentrep))
generate	TUREnt_2	= TU_rate/(frac_HHentrep + 0.1*(1-frac_HHentrep))
generate	TUREnt_3	= TU_rate/(frac_HHentrep + 0.2*(1-frac_HHentrep))
generate	TUREnt_4	= TU_rate/(frac_HHentrep + 0.3*(1-frac_HHentrep))
generate	TUREnt_5	= TU_rate/(frac_HHentrep + 0.4*(1-frac_HHentrep))
generate	TUREnt_6	= TU_rate/(frac_HHentrep + 0.5*(1-frac_HHentrep))
generate	TUREnt_7	= TU_rate/(frac_HHentrep + 0.6*(1-frac_HHentrep))
generate	TUREnt_8	= TU_rate/(frac_HHentrep + 0.7*(1-frac_HHentrep))
generate	TUREnt_9	= TU_rate/(frac_HHentrep + 0.8*(1-frac_HHentrep))
generate	TUREnt_10	= TU_rate/(frac_HHentrep + 0.9*(1-frac_HHentrep))
generate	TUREnt_11	= TU_rate/(frac_HHentrep + 1*(1-frac_HHentrep))

label var TUREnt_8 "Take-up"
label var TUREnt_4 "Take-up"

gen information = .
gen incentives  = .
replace information	= 1 if public	== 1
replace information	= 2 if private	== 1
replace incentives	= 1 if high		== 1
replace incentives	= 2 if low		== 1

foreach x of varlist TUREnt_4 {

	local axisY : var label `x'

	ttest `x' if private == 1, by(incentives)
	local diff1 = r(mu_1)-r(mu_2)
	local se1 = r(se)
	local pv1: di %6.3fc r(p)

	ttest `x' if public == 1, by(incentives)
	local diff2 = r(mu_1)-r(mu_2)
	local se2 = r(se)
	local pv2: di %6.3fc r(p)

	ttest `x' if high == 1, by(information)
	local pv3: di %6.3fc r(p)

	ttest `x' if low == 1, by(information)
	local pv4: di %6.3fc r(p)

	local pv5: di %6.3fc 2*(1-normal(abs((`diff1'-`diff2')/sqrt(`se1'^2+`se2'^2))))

	preserve

		collapse (mean) mean_`x' = `x' (sd) sd_`x' = `x' (count) n = `x', by(information incentives)
		generate h`x' = mean_`x' + invttail(n-1,0.025)*(sd_`x' / sqrt(n))
		generate l`x' = mean_`x' - invttail(n-1,0.025)*(sd_`x' / sqrt(n))

		*------------------------ FORMAT
		* AXIS
		local vmin_axis = 0
		local vmax_axis = 0.15
		foreach i in 1 2 3 {
			local k = `i' - 1
			local v_axis`i' = `vmax_axis'-`k'*0.01
			local aux_v`i'  = `v_axis`i''-0.001
		}

		* NUMBER OF TICKS 5/6
		local pr_axis: di %6.2fc (`vmax_axis'-(`vmin_axis'))/5

		*------------------------ FIGURE
		generate infinc = incentives    if information == 2 // private first
		replace  infinc = incentives+3  if information == 1 // public second
		
		sort infinc
		
		twoway (bar mean_`x' infinc if incentives==1,  lcolor(black) fcolor(erose)) ///
		       (bar mean_`x' infinc if incentives==2, lcolor(black) fcolor(gs14)) ///
		       (rcap h`x' l`x' infinc), xlabel( 1.5 "Private" 4.5 "Public") ///
		        legend( order(1 "High Incentives" 2 "Low Incentives")) ///		
		       ytitle(`axisY') xtitle("") ylabel(`vmin_axis'(`pr_axis')`vmax_axis') 
			   
		gr_edit style.editstyle boxstyle(shadestyle(color(white))) editcopy
		gr_edit style.editstyle boxstyle(linestyle(color(white))) editcopy

		* P-VALUES
		local k = 0
		foreach y in 1.2 4.2 2.2 3.2 {
			local k=`k'+1
			if `k' == 1 | `k' == 2 {
				local axis`k' = `v_axis1'
			}
			if `k' == 3 | `k' == 4 {
				local j = `k'-1
				local axis`k' = `v_axis`j''
			}
			gr_edit plotregion1.AddTextBox added_text editor `axis`k'' `y'
			gr_edit plotregion1.added_text[`k'].text.Arrpush p=`pv`k''
		}

		* FIRST LINE
		foreach xa of numlist 1 1.82 4 4.82 {
			local x2 = `xa' + 0.18
			if `xa' == 1 | `xa' == 4 {
				local xv = `xa'
			}
			else {
				local xv = `x2'
			}
			gr_edit plotregion1.AddLine added_lines editor `xa' `v_axis1' `x2' `v_axis1'
			gr_edit plotregion1.AddLine added_lines editor `xv' `v_axis1' `xv' `aux_v1'
		}

		* SECOND LINE
		foreach xa of numlist 1 2.82 {
			local x2 = `xa' + 1.18
			if `xa' == 1 {
				local xv = `xa'
			}
			else {
				local xv = `x2'
			}
			gr_edit plotregion1.AddLine added_lines editor `xa' `v_axis2' `x2' `v_axis2'
			gr_edit plotregion1.AddLine added_lines editor `xv' `v_axis2' `xv' `aux_v2'
		}

		* THIRD LINE
		foreach xa of numlist 2 3.82 {
			local x2 = `xa' + 1.18
			if `xa' == 2 {
				local xv = `xa'
			}
			else {
				local xv=`x2'
			}
			gr_edit plotregion1.AddLine added_lines editor `xa' `v_axis3' `x2' `v_axis3'
			gr_edit plotregion1.AddLine added_lines editor `xv' `v_axis3' `xv' `aux_v3'
		}
		graph export "$FIG/FigureA7.png", replace

	restore
}
*/

* ==============================================================================
* TABLE A1: SUMMARY STATISTICS AND BALANCE CHECKS
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

*------------------------ SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5 svar1-svar3

*------------------------ VARIABLES
* VILLAGE AND AGENT
local Bal1 "BLnbHH BLdistance BLinternet_coverage BLgender BLprimary BLhighschool BLtertiary BLbusiness BLagother BLvolunteer BLmobile BLcomputer"

* HOUSEHOLD
local Bal2 "BLgender BLprimary BLhighschool BLtertiary BLbusiness BLagother BLvolunteer BLmobile BLcomputer BLbankTrans BLsavebank BLtrust_state_bank BLtrust_nonstate_bank BLknow_mobile_bk BLknows_agn BLclose_agn"

local k = 0
forval i = 1/2 {
	
	if `i' == 1 {
		use "$OUT/admin_data_vill_final_all.dta", clear
	}
	else {
		use "$OUT/master_admin_final.dta", clear
	}

	label var BLnbHH "Village Size"

	foreach x in `Bal`i'' {
		
		local k = `k' + 1 

		local dm  = 3
		local dsd = 3

		if `i' == 1 {
			if `x' == BLnbHH {
				local dm  = 1
				local dsd = 1 
			}
			if `x' == BLdistance {
				local dm  = 2
				local dsd = 3
			} 
			if  `x' != BLnbHH & `x' != BLdistance {
				local dm  = 3
				local dsd = 3
			} 
		}

		local lbl_`k': var label `x'

		* MODEL
		reg `x' high_private high_public low_public `controls',  cl(agn_cl)
		
		* OBSERVATIONS
		local C1R`k':  di e(N)

		* MEAN
		sum `x' 
		local C2R`k':  di %12.`dm'fc r(mean)
		local C3R`k':  di %12.`dsd'fc r(sd)
		 
		* TEST
		local c = 3
		foreach t in "high_private high_public low_public" "high_private" "high_public-low_public=0" ///
		"high_public-high_private=0" "low_public" {
			local c = `c' + 1
			test `t'
			local C`c'R`k':  di %12.3fc r(p)
		}

		* ADD STARS IF CORRESPONDS
		foreach j of numlist 5 6 7 8 {
			if `C`j'R`k'' <= 0.10 & `C`j'R`k'' > 0.05 {
				local C`j'R`k' = "$`C`j'R`k''^{*}$"
			}
			else if `C`j'R`k'' <= 0.05 & `C`j'R`k'' > 0.01 {
				local C`j'R`k'="$`C`j'R`k''^{**}$"
			}
			else if `C`j'R`k'' <= 0.01 { 
				local C`j'R`k' = "$`C`j'R`k''^{***}$"
			}
		}
	}
}

*------------------------ CREATE LATEX OUTPUT FILE 
texdoc init "$TEX/TableA1.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\
tex  \\ [-1.5ex]
tex & {\makecell{Obs.}} & {\makecell{Mean}} & {\makecell{Std. Dev.}} & \makecell{p-value \\ F-stat \\ Joint} & {\makecell{p-value \\ (High-Low)$\ensuremath{\times}$ \\ Private}} & {\makecell{p-value \\ (High-Low)$\ensuremath{\times}$ \\ Public}} &  {\makecell{p-value \\ (Public-Private)$\ensuremath{\times}$ \\ High}}  &  {\makecell{p-value \\ (Public-Private)$\ensuremath{\times}$ \\ Low}} \\\\
tex \multicolumn{1}{l}{\textbf{Panel A: Village Characteristics}} \\
forvalue t = 1/3 {
tex `lbl_`t'' & `C1R`t''& `C2R`t''  & `C3R`t''  & `C4R`t''  & `C5R`t''& `C6R`t'' & `C7R`t'' & `C8R`t''  \\
}
tex \\
tex \multicolumn{1}{l}{\textbf{Panel B: Agent Characteristics}} \\
forvalue t = 4/12 {
tex `lbl_`t'' & `C1R`t''& `C2R`t''  & `C3R`t''  & `C4R`t''  & `C5R`t''& `C6R`t'' & `C7R`t'' & `C8R`t''  \\
}
tex \\
tex \multicolumn{1}{l}{\textbf{Panel C: Household Characteristics}} \\
forvalue t = 13/28 {
tex `lbl_`t'' & `C1R`t''& `C2R`t''  & `C3R`t''  & `C4R`t''  & `C5R`t''& `C6R`t'' & `C7R`t'' & `C8R`t''  \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE A2: SUMMARY STATISTICS BY TREATMENT (BASELINE)
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5 svar1-svar3

* VILLAGE AND AGENT
local Bal1 "BLnbHH BLdistance BLinternet_coverage BLgender BLprimary BLhighschool BLtertiary BLbusiness BLagother BLvolunteer BLmobile BLcomputer"

* HOUSEHOLD
local Bal2 "BLgender BLprimary BLhighschool BLtertiary BLbusiness BLagother BLvolunteer BLmobile BLcomputer BLbankTrans BLsavebank BLtrust_state_bank BLtrust_nonstate_bank BLknow_mobile_bk BLknows_agn BLclose_agn"

local k = 0
forval i = 1/2 {

	if `i' == 1 {
		use "$OUT/admin_data_vill_final_all.dta", clear
	}
	else {
		use "$OUT/master_admin_final.dta", clear
	}

	label var BLnbHH "Village Size"

	foreach x in `Bal`i''  {
	
		local k = `k' + 1 

		local dm  = 3
		local dsd = 3

		if `i'==1 {
			if `x' == BLnbHH {
				local dm  = 1
				local dsd = 1 
			}
			if `x' == BLdistance {
				local dm  = 2
				local dsd = 3
			} 
			if  `x' != BLnbHH & `x' != BLdistance {
				local dm  = 3
				local dsd = 3
			} 
		}

		local lbl_`k' :var label `x'

		local j = 0

		foreach var in high_private low_private high_public low_public {
		
			sum `x' if `var' == 1
			local j = `j' + 1
			local C`j'R`k':  di %12.0fc r(N)
			local j = `j' + 1
			local C`j'R`k':  di %12.`dm'fc r(mean)
			local j = `j' + 1
			local C`j'R`k':  di %12.`dsd'fc r(sd)
		
		}
	}
}

*------------------------ CREATE LATEX PUTPUT FILE
texdoc init "$TEX/TableA2.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3) & & (4) & (5) & (6) & & (7) & (8) & (9) & & (10) & (11) & (12)  \\\\
tex  & \multicolumn{3}{c}{High $\ensuremath{\times}$ Private} & & \multicolumn{3}{c}{Low $\ensuremath{\times}$ Private} & & \multicolumn{3}{c}{High $\ensuremath{\times}$ Public} & & \multicolumn{3}{c}{Low $\ensuremath{\times}$ Public}   \\
tex \cline{2-4} \cline{6-8} \cline{10-12} \cline{14-16}
tex  \\ [-1.5ex]
tex & {Obs.} & {Mean}  & {Std. Dev.} & & {Obs.} & {Mean}  & {Std. Dev.} & & {Obs.} & {Mean}  & {Std. Dev.} & & {Obs.} & {Mean}  & {Std. Dev.}  \\\\
tex \multicolumn{1}{l}{\textbf{Panel A: Village Characteristics}} \\
forvalue t = 1/3 {
tex `lbl_`t'' & `C1R`t''& `C2R`t''  & `C3R`t'' &  & `C4R`t''  & `C5R`t''& `C6R`t''  & & `C7R`t''  & `C8R`t'' & `C9R`t'' &  & `C10R`t''  & `C11R`t'' & `C12R`t''   \\
}
tex \\
tex \multicolumn{1}{l}{\textbf{Panel B: Agent Characteristics}} \\
forvalue t = 4/12 {
tex `lbl_`t'' & `C1R`t''& `C2R`t''  & `C3R`t'' &  & `C4R`t''  & `C5R`t''& `C6R`t''  & & `C7R`t''  & `C8R`t'' & `C9R`t'' &  & `C10R`t''  & `C11R`t'' & `C12R`t''   \\
}
tex \\
tex \multicolumn{1}{l}{\textbf{Panel C: Household Characteristics}} \\
forvalue t = 13/28 {
tex `lbl_`t'' & `C1R`t''& `C2R`t''  & `C3R`t'' &  & `C4R`t''  & `C5R`t''& `C6R`t''  & & `C7R`t''  & `C8R`t'' & `C9R`t'' &  & `C10R`t''  & `C11R`t'' & `C12R`t''   \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE A3: SUMMARY STATISTICS OF MAIN OUTCOME VARIABLES BY TREATMENT (ENDLINE)
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

collapse (mean) EL_takeupBM BLnbHH, by(agn_cl)
gen TU_level = EL_takeupBM * BLnbHH
label var TU_level "Number of People in the Village who Take-Up"
merge 1:1 agn_cl using "$OUT/admin_data_vill_final_all.dta"
tempfile takeup_level
save `takeup_level'

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5 svar1-svar3

* VILLAGE AND AGENT
local Bal1 "TU_level "

* HOUSEHOLD

** NOTE: THE ORIGINAL CODE INCLUDES THE FOLLOWING:
** local Bal2 "EL_takeupBM ADamount_ihs ADbalance_ihs EL_saving_ihs EL_effort_agent_talk EL_heard_agn EL_pcaEffort EL_offer_prod EL_agn_convince EL_pcaStyle EL_agn_earning EL_pcaProduct EL_pcaBank EL_pcaAgent EL_pcaAll"
** THIS HAS BEEN MODIFIED TO EXCLUDE VARIABLES COMING FROM THE ADMINISTRATIVE DATASET, WHICH CAN'T BE PUBLICLY SHARED.

local Bal2 "EL_takeupBM EL_saving_ihs EL_effort_agent_talk EL_heard_agn EL_pcaEffort EL_offer_prod EL_agn_convince EL_pcaStyle EL_agn_earning EL_pcaProduct EL_pcaBank EL_pcaAgent EL_pcaAll"

local k = 1
forval i = 1/2 {
	
	if `i' == 1 {
		
		foreach x in `Bal`i'' {
			
			use `takeup_level', clear
		
			local j=0
			
			foreach var in high_private low_private high_public low_public {

				sum `x' if `var' == 1
				local j = `j' + 1
				local C`j'R`k':  di %12.0fc r(N)
				local j = `j' + 1
				local C`j'R`k':  di %12.3fc r(mean)
				local j = `j' + 1
				local C`j'R`k':  di %12.3fc r(sd)
				local lbl_`k' :  var label `x'

			}
		}
	}

	else {
		
		use "$OUT/master_admin_final.dta", clear

		foreach x in `Bal`i''  {

			local k = `k' + 1 

			local lbl_`k' : var label `x'

			local j = 0
			foreach var in high_private low_private high_public low_public {
				sum `x' if `var' == 1
				local j = `j' + 1
				local C`j'R`k':  di %12.0fc r(N)
				local j = `j' + 1
				local C`j'R`k':  di %12.3fc r(mean)
				local j = `j' + 1
				local C`j'R`k':  di %12.3fc r(sd)
			}
		}

	}

}

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/TableA3.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3) & & (4) & (5) & (6) & & (7) & (8) & (9) & & (10) & (11) & (12)  \\\\
tex  & \multicolumn{3}{c}{High $\ensuremath{\times}$ Private} & & \multicolumn{3}{c}{Low $\ensuremath{\times}$ Private} & & \multicolumn{3}{c}{High $\ensuremath{\times}$ Public} & & \multicolumn{3}{c}{Low $\ensuremath{\times}$ Public}   \\
tex \cline{2-4} \cline{6-8} \cline{10-12} \cline{14-16}
tex  \\ [-1.5ex]
tex & {Obs.} & {Mean}  & {Std. Dev.} & & {Obs.} & {Mean}  & {Std. Dev.} & & {Obs.} & {Mean}  & {Std. Dev.} & & {Obs.} & {Mean}  & {Std. Dev.}  \\\\
tex \multicolumn{1}{l}{\textbf{Panel A: Village Level Adoption}} \\
forvalue t = 1/1 {
tex `lbl_`t'' & `C1R`t''& `C2R`t''  & `C3R`t'' &  & `C4R`t''  & `C5R`t''& `C6R`t''  & & `C7R`t''  & `C8R`t'' & `C9R`t'' &  & `C10R`t''  & `C11R`t'' & `C12R`t''   \\
}
tex \\
tex \multicolumn{1}{l}{\textbf{Panel B: Take-up and Usage}} \\
forvalue t = 2/5 {
tex `lbl_`t'' & `C1R`t''& `C2R`t''  & `C3R`t'' &  & `C4R`t''  & `C5R`t''& `C6R`t''  & & `C7R`t''  & `C8R`t'' & `C9R`t'' &  & `C10R`t''  & `C11R`t'' & `C12R`t''   \\
}
tex \\
tex \multicolumn{1}{l}{\textbf{Panel C: Agent Effort}} \\
forvalue t = 6/11 {
tex `lbl_`t'' & `C1R`t''& `C2R`t''  & `C3R`t'' &  & `C4R`t''  & `C5R`t''& `C6R`t''  & & `C7R`t''  & `C8R`t'' & `C9R`t'' &  & `C10R`t''  & `C11R`t'' & `C12R`t''   \\
}
tex \\
tex \multicolumn{1}{l}{\textbf{Panel D: Trust}} \\
forvalue t = 12/16 {
tex `lbl_`t'' & `C1R`t''& `C2R`t''  & `C3R`t'' &  & `C4R`t''  & `C5R`t''& `C6R`t''  & & `C7R`t''  & `C8R`t'' & `C9R`t'' &  & `C10R`t''  & `C11R`t'' & `C12R`t''   \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE A4: MAIN RESULTS – MULTIPLE HYPOTHESIS TESTING (P-VALUES)
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5 svar1-svar3

* COMPUTE COVARIANCE TO USE IN BOOTSTRAP THEN 
local k = 0

** NOTE: THE ORIGINAL CODE INCLUDES THE FOLLOWING:
** foreach y of varlist EL_takeupBM  ADntransBM ADamount_ihs ADbalance_ihs EL_saving_ihs ///
		*			 EL_effort_agent_talk EL_heard_agn EL_pcaEffort EL_offer_prod ///
		*			 EL_agn_convince EL_pcaStyle EL_agn_earning EL_pcaProduct EL_pcaBank ///
		*			 EL_pcaAgent EL_pcaAll {

** THIS HAS BEEN MODIFIED TO EXCLUDE VARIABLES COMING FROM THE ADMINISTRATIVE DATASET, WHICH CAN'T BE PUBLICLY SHARED.

foreach y of varlist EL_takeupBM  EL_saving_ihs ///
					 EL_effort_agent_talk EL_heard_agn EL_pcaEffort EL_offer_prod ///
					 EL_agn_convince EL_pcaStyle EL_agn_earning EL_pcaProduct EL_pcaBank ///
					 EL_pcaAgent EL_pcaAll {
	
	local k = `k' + 1
	cap reg `y' high_public low_public high_private  `controls',  cl(agn_cl) 
	matrix V = e(V)
	/* beta */ 	local beta`k' = _b[high_public]-_b[low_public]-_b[high_private]
	/*v*/   	local v`k' = -2*V[2,1]-2*V[3,1]+2*V[3,2]
	/* se*/    	local se`k' = sqrt(V[1,1]+V[2,2]+V[3,3]-2*V[2,1]-2*V[3,1]+2*V[3,2])

}

*------------------------ MULTIPLE HYPOTHESIS TESTING ROMANO AND WOLF METHOD
* (HIGH-LOW)*PRIVATE
* Corrected p-values for each section:

** NOTE: THE ORIGINAL CODE INCLUDES THE FOLLOWING:
** rwolf EL_takeupBM  ADntransBM ADamount_ihs ADbalance_ihs EL_saving_ihs, indepvar(high_private) controls(high_public low_public `controls') strata(`controls') reps(100) vce(cluster agn_cl) seed(1)

** THIS HAS BEEN MODIFIED TO EXCLUDE VARIABLES COMING FROM THE ADMINISTRATIVE DATASET, WHICH CAN'T BE PUBLICLY SHARED.

rwolf EL_takeupBM EL_saving_ihs, indepvar(high_private) controls(high_public low_public `controls') strata(`controls') reps(100) vce(cluster agn_cl) seed(1)
local k = 0
** NOTE: THE ORIGINAL CODE INCLUDES THE FOLLOWING:
** foreach x of varlist EL_takeupBM  ADntransBM ADamount_ihs ADbalance_ihs EL_saving_ihs  {

** THIS HAS BEEN MODIFIED TO EXCLUDE VARIABLES COMING FROM THE ADMINISTRATIVE DATASET, WHICH CAN'T BE PUBLICLY SHARED.
foreach x of varlist EL_takeupBM  EL_saving_ihs  {
	local k = `k' + 1
	local lbl_`k' : var label `x'
	/*pv (H-L)Pu*/ local C1R`k': di %12.3fc e(rw_`x')
}

rename EL_effort_agent_talk EL_effort_agent // name too large 
rwolf EL_effort_agent EL_heard_agn EL_pcaEffort EL_offer_prod EL_agn_convince EL_pcaStyle, indepvar(high_private) controls(high_public low_public `controls') strata(`controls') reps(100) vce(cluster agn_cl) seed(1)
foreach x of varlist EL_effort_agent EL_heard_agn EL_pcaEffort EL_offer_prod EL_agn_convince EL_pcaStyle {
	local k = `k' + 1
	local lbl_`k' : var label `x'
	/*pv (H-L)Pu*/ local C1R`k': di %12.3fc e(rw_`x')
}
rwolf EL_agn_earning EL_pcaProduct EL_pcaBank EL_pcaAgent EL_pcaAll, indepvar(high_private)  controls(high_public low_public `controls') reps(100) vce(cluster agn_cl) seed(1)
foreach x of varlist EL_agn_earning EL_pcaProduct EL_pcaBank EL_pcaAgent EL_pcaAll {
	local k = `k' + 1
	local lbl_`k' : var label `x'
	/*pv (H-L)Pu*/ local C1R`k': di %12.3fc e(rw_`x')
}

* (HIGH-LOW)*PUBLIC
* Corrected p-values for each section:

** NOTE: THE ORIGINAL CODE INCLUDES THE FOLLOWING:
** rwolf EL_takeupBM  ADntransBM ADamount_ihs ADbalance_ihs EL_saving_ihs, indepvar(high_public)  controls(high_private low_private `controls') strata(`controls') reps(100) vce(cluster agn_cl) seed(1)

** THIS HAS BEEN MODIFIED TO EXCLUDE VARIABLES COMING FROM THE ADMINISTRATIVE DATASET, WHICH CAN'T BE PUBLICLY SHARED.

rwolf EL_takeupBM EL_saving_ihs, indepvar(high_public)  controls(high_private low_private `controls') strata(`controls') reps(100) vce(cluster agn_cl) seed(1)
local k = 0
** NOTE: THE ORIGINAL CODE INCLUDES THE FOLLOWING:
** foreach x of varlist EL_takeupBM  ADntransBM ADamount_ihs ADbalance_ihs EL_saving_ihs {

** THIS HAS BEEN MODIFIED TO EXCLUDE VARIABLES COMING FROM THE ADMINISTRATIVE DATASET, WHICH CAN'T BE PUBLICLY SHARED.
foreach x of varlist EL_takeupBM EL_saving_ihs {
	local k =`k' + 1
	local lbl_`k' : var label `x'
	/*pv (H-L)Pu*/ local C2R`k': di %12.3fc e(rw_`x')
}

rwolf EL_effort_agent EL_heard_agn EL_pcaEffort EL_offer_prod EL_agn_convince EL_pcaStyle, indepvar(high_public)  controls(high_private low_private `controls') strata(`controls') reps(100) vce(cluster agn_cl) seed(1)
foreach x of varlist EL_effort_agent EL_heard_agn EL_pcaEffort EL_offer_prod EL_agn_convince EL_pcaStyle {
	local k = `k' + 1
	local lbl_`k' : var label `x'
	/*pv (H-L)Pu*/ local C2R`k': di %12.3fc e(rw_`x')
}
rwolf EL_agn_earning EL_pcaProduct EL_pcaBank EL_pcaAgent EL_pcaAll, indepvar(high_public)  controls(high_private low_private `controls') strata(`controls') reps(100) vce(cluster agn_cl) seed(1)
foreach x of varlist EL_agn_earning EL_pcaProduct EL_pcaBank EL_pcaAgent EL_pcaAll {
	local k = `k' + 1
	local lbl_`k' : var label `x'
	/*pv (H-L)Pu*/ local C2R`k': di %12.3fc e(rw_`x')
}

* (H-L)*PUBLIC-(H-L)*PRIVATE 
* Bootstrap for diff in diff
local k = 0
** NOTE: THE ORIGINAL CODE INCLUDES THE FOLLOWING:
** foreach x of varlist EL_takeupBM  ADntransBM ADamount_ihs ADbalance_ihs EL_saving_ihs EL_effort_agent EL_heard_agn EL_pcaEffort ///
			*		 EL_offer_prod EL_agn_convince EL_pcaStyle EL_agn_earning EL_pcaProduct EL_pcaBank EL_pcaAgent EL_pcaAll {

** THIS HAS BEEN MODIFIED TO EXCLUDE VARIABLES COMING FROM THE ADMINISTRATIVE DATASET, WHICH CAN'T BE PUBLICLY SHARED.

foreach x of varlist EL_takeupBM  EL_saving_ihs EL_effort_agent EL_heard_agn EL_pcaEffort ///
					 EL_offer_prod EL_agn_convince EL_pcaStyle EL_agn_earning EL_pcaProduct EL_pcaBank EL_pcaAgent EL_pcaAll {
	local k = `k' + 1
	bootstrap beta`k' = (_b[high_public]-_b[low_public]-_b[high_private]) ///
	se`k' = (sqrt(_se[high_public]^2+_se[low_public]^2+_se[high_private]^2+`v`k'')), ///
	saving("$TEMP/bootstrap`k'.dta", replace) reps(180) seed(1): reg `x' high_public low_public high_private `controls',  cl(agn_cl) 
}

* Corrected p-values for each section:
use  "$TEMP/bootstrap1.dta", clear
forval i = 2/`k' {
	append using "$TEMP/bootstrap`i'.dta"
}

rwolf beta1 beta2 beta3 beta4 beta5, pointestimates(`beta1' `beta2' `beta3' `beta4' `beta5') stderrs(`se1' `se2' `se3' `se4' `se5') nobootstraps stdests(se1 se2 se3 se4 se5)
local k = 0
foreach x of varlist beta1 beta2 beta3 beta4 beta5  {
	local k = `k' + 1
	/*pv (H-L)Pu*/ local C3R`k': di %12.3fc e(rw_`x')
}

rwolf beta6 beta7 beta8 beta9 beta10 beta11, pointestimates(`beta6' `beta7' `beta8' `beta9' `beta10' `beta11') stderrs(`se6' `se7' `se8' `se9' `se10' `se11') nobootstraps stdests(se6 se7 se8 se9 se10 se11)
foreach x of varlist beta6 beta7 beta8 beta9 beta10 beta11 {
	local k = `k' + 1
	/*pv (H-L)Pu*/ local C3R`k': di %12.3fc e(rw_`x')
}

rwolf beta12 beta13 /* beta14 beta15 beta16 */, pointestimates(`beta12' `beta13' /* `beta14' `beta15' `beta16' */) stderrs(`se12' `se13' /* `se14' `se15' `se16' */) nobootstraps stdests(se12 se13 /* se14 se15 se16 */)
foreach x of varlist beta12 beta13 /* beta14 beta15 beta16 */ {
	local k = `k' + 1
	/*pv (H-L)Pu*/ local C3R`k': di %12.3fc e(rw_`x')
}

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/TableA4.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3)  \\\\
tex  \\ [-1.5ex]
tex  & \makecell{(High - Low) $\ensuremath{\times}$ \\ Private} & \makecell{(High - Low) $\ensuremath{\times}$ \\ Public} & \makecell{(High - Low) $\ensuremath{\times}$ \\ (Public - Private)}  \\\\
tex  \hline \\ 
tex \\
tex \multicolumn{1}{l}{\textbf{Panel A. Take-up}} \\
local t=1
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''    \\
tex  \\
tex \multicolumn{1}{l}{\textbf{Panel B. Agent Effort}} \\
forvalue t=6/8 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''    \\
}
tex  \\
tex \multicolumn{1}{l}{\textbf{Panel C. Agent Sales Strategy}} \\
forvalue t=9/11 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''    \\
}
tex  \\
tex \multicolumn{1}{l}{\textbf{Panel D. Perceptions}} \\
forvalue t=12/16 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''    \\
}
tex \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE A5: MAIN RESULTS – EXTRA CONTROLS
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5  svar1-svar3 BLvolunteer BLgender BLcomputer_agn BLknow_mobile_bk BLknows_agn 

local k = 0
foreach y of varlist EL_takeupBM EL_effort_agent_talk EL_heard_agn EL_pcaEffort EL_offer_prod EL_agn_convince ///
			   		 EL_pcaStyle EL_agn_earning EL_pcaProduct EL_pcaBank EL_pcaAgent EL_pcaAll {
	
	local k = `k' + 1
	
	local outcome_`k' : var label `y'
	
	* MODEL
	reg `y' high_private high_public low_public `controls',  cl(agn_cl) 

	* MAIN ESTIMATES
	local v = 0
	
	foreach t in "high_private" "high_public-low_public" "high_public-low_public-high_private" {
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*B*/    	local C`k'R`b' : di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s' : di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}


	* FORMAT SE ()
	foreach j of numlist 2 4 6 {
		local C`k'R`j': di trim("`C`k'R`j''")
		local C`k'R`j' = "(`C`k'R`j'')"
	}
			
	* ADD STARS IF CORRESPONDS
	foreach j of numlist 1 3 5 {
		if `pv`k'R`j'' <= 0.10 & `pv`k'R`j'' > 0.05 {
			local C`k'R`j' = "$`C`k'R`j''^{*}$"
		}
		else if `pv`k'R`j'' <= 0.05 & `pv`k'R`j'' > 0.01 {
			local C`k'R`j' = "$`C`k'R`j''^{**}$"
		}
		else if `pv`k'R`j'' <= 0.01 { 
			local C`k'R`j' = "$`C`k'R`j''^{***}$"
		}
	}

}

* ROW TITLES
local lbl_1 "(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 "(High - Low) $\ensuremath{\times}$ Public"
local lbl_3 "(High - Low) $\ensuremath{\times}$ (Public - Private)"  
		
*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/TableA5.tex", replace force
tex  \\ [-1.5ex] 
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3)   \\\\
tex  \\ [-1.5ex]
tex  & `lbl_1' & `lbl_2' & `lbl_3' \\\\
tex  \hline \\ 
tex \multicolumn{1}{l}{\textbf{Panel A. Take-up}} \\
tex  \\ [-1.5ex]
loc t = 1 
tex `outcome_`t''  & `C`t'R1'  & `C`t'R3'  & `C`t'R5'    \\
tex                & `C`t'R2'  & `C`t'R4'  & `C`t'R6'     \\

tex \multicolumn{1}{l}{\textbf{Panel B. Agent Effort}} \\
tex  \\ [-1.5ex]
forvalue t = 2/4 {
tex `outcome_`t''  & `C`t'R1'  & `C`t'R3'  & `C`t'R5'    \\
tex                & `C`t'R2'  & `C`t'R4'  & `C`t'R6'     \\
}
tex \multicolumn{1}{l}{\textbf{Panel C. Agent Sales Strategy}} \\
tex  \\ [-1.5ex]
forvalue t = 5/7 {
tex `outcome_`t''  & `C`t'R1'  & `C`t'R3'  & `C`t'R5'    \\
tex                & `C`t'R2'  & `C`t'R4'  & `C`t'R6'     \\
}
tex \multicolumn{1}{l}{\textbf{Panel D. Perceptions}} \\
tex  \\ [-1.5ex]
forvalue t = 8/12 {
tex `outcome_`t''  & `C`t'R1'  & `C`t'R3'  & `C`t'R5'    \\
tex                & `C`t'R2'  & `C`t'R4'  & `C`t'R6'     \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE A6: MAIN RESULTS – WEIGHTED
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

gen weight = (BLnbHH/12)

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5  svar1-svar3 

local k = 0

foreach y of varlist EL_takeupBM EL_effort_agent_talk EL_heard_agn EL_pcaEffort ///
					 EL_offer_prod EL_agn_convince EL_pcaStyle EL_agn_earning ///
					 EL_pcaProduct EL_pcaBank EL_pcaAgent EL_pcaAll {
	
	local k = `k' + 1

	local outcome_`k' : var label `y'
	
	* MODEL
	reg `y' high_private high_public low_public `controls' [pweight=weight], cl(agn_cl) 

	* MAIN ESTIMATES
	local v = 0
	
	foreach t in "high_private" "high_public-low_public" "high_public-low_public-high_private" {
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*B*/    	local C`k'R`b' :  di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s' :  di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* FORMAT SE ()
	foreach j of numlist 2 4 6 {
		local C`k'R`j': di trim("`C`k'R`j''")
		local C`k'R`j' = "(`C`k'R`j'')"
	}
			
	* ADD STARS IF CORRESPONDS
	foreach j of numlist 1 3 5 {
		if `pv`k'R`j'' <= 0.10 & `pv`k'R`j'' > 0.05 {
			local C`k'R`j' = "$`C`k'R`j''^{*}$"
		}
		else if `pv`k'R`j'' <= 0.05 & `pv`k'R`j'' > 0.01 {
			local C`k'R`j' = "$`C`k'R`j''^{**}$"
		}
		else if `pv`k'R`j'' <= 0.01 { 
			local C`k'R`j' = "$`C`k'R`j''^{***}$"
		}
	}

}

* ROW TITLES
local lbl_1 "(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 "(High - Low) $\ensuremath{\times}$ Public"
local lbl_3 "(High - Low) $\ensuremath{\times}$ (Public - Private)"  
		
*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/TableA6.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3)   \\\\
tex  \\ [-1.5ex]
tex  & `lbl_1' & `lbl_2' & `lbl_3' \\\\
tex  \hline \\ 
tex \multicolumn{1}{l}{\textbf{Panel A. Take-up}} \\
tex  \\ [-1.5ex]
loc t = 1 
tex `outcome_`t''  & `C`t'R1'  & `C`t'R3'  & `C`t'R5'    \\
tex                & `C`t'R2'  & `C`t'R4'  & `C`t'R6'     \\

tex \multicolumn{1}{l}{\textbf{Panel B. Agent Effort}} \\
tex  \\ [-1.5ex]
forvalue t = 2/4 {
tex `outcome_`t''  & `C`t'R1'  & `C`t'R3'  & `C`t'R5'    \\
tex                & `C`t'R2'  & `C`t'R4'  & `C`t'R6'     \\
}
tex \multicolumn{1}{l}{\textbf{Panel C. Agent Sales Strategy}} \\
tex  \\ [-1.5ex]
forvalue t = 5/7 {
tex `outcome_`t''  & `C`t'R1'  & `C`t'R3'  & `C`t'R5'    \\
tex                & `C`t'R2'  & `C`t'R4'  & `C`t'R6'     \\
}
tex \multicolumn{1}{l}{\textbf{Panel D. Perceptions}} \\
tex  \\ [-1.5ex]
forvalue t = 8/12 {
tex `outcome_`t''  & `C`t'R1'  & `C`t'R3'  & `C`t'R5'    \\
tex                & `C`t'R2'  & `C`t'R4'  & `C`t'R6'     \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE A7: TAKE-UP OF OTHER PRODUCTS
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5 svar1-svar3

local k = 0

foreach y of varlist EL_takeupnoBM_mb EL_other_fin_prods EL_bank EL_saving_branch_ihs {
	
	local k = `k' + 1

	local outcome_`k' : var label `y'
	
	* MODEL
	reg `y' high_private high_public low_public  `controls',  cl(agn_cl) 

	* MAIN ESTIMATES
	local v = 0

	foreach t in "high_private" "high_public-low_public" "high_public-low_public-high_private" {
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b' : di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s' : di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* REGRESSION COEFFICIENTS
	foreach t in high_private high_public low_public {
		local v = `v' + 1
		local b = 2*`v' - 1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b' : di %12.3fc _b[`t']
		/*se*/ 		local C`k'R`s' : di %12.3fc _se[`t']
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(_b[`t']/_se[`t'])))
	}

	* OBSERVATIONS
	local C`k'R13:  di e(N)

	* R2
	local C`k'R14:  di %12.3fc e(r2)

	* MEAN DEP VARIABLE
	sum `y' 
	local C`k'R15:  di %12.3fc r(mean)

	* MEAN DEP VARIABLE FOR LOW PRIVATE
	sum `y' if low_private == 1
	local C`k'R16:  di %12.3fc r(mean)

	* T-TEST HIGH PRIVATE - HIGH PUBLIC
	test high_private = high_public 
	local C`k'R17:  di %12.3fc r(p)

	* T-TEST HIGH PRIVATE - LOW PUBLIC
	test high_private = low_public 
	local C`k'R18:  di %12.3fc r(p)

	*------------------------ FORMATTING
	* FORMAT SE ()
	foreach j of numlist 2 4 6 8 10 12 {
		local C`k'R`j': di trim("`C`k'R`j''")
		local C`k'R`j' = "(`C`k'R`j'')"
	}
			
	* ADD STARS IF CORRESPONDS	
	foreach j of numlist 1 3 5 7 9 11 {
		if `pv`k'R`j'' <= 0.10 & `pv`k'R`j'' > 0.05 {
			local C`k'R`j' = "$`C`k'R`j''^{*}$"
		}
		else if `pv`k'R`j'' <= 0.05 & `pv`k'R`j'' > 0.01 {
			local C`k'R`j' = "$`C`k'R`j''^{**}$"
		}
		else if `pv`k'R`j'' <= 0.01 { 
			local C`k'R`j' = "$`C`k'R`j''^{***}$"
		}
	}

}

*------------------------ ROW TITLES
local lbl_1 "(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 ""	
local lbl_3 "(High - Low) $\ensuremath{\times}$ Public"
local lbl_4 "" 
local lbl_5 "(High - Low) $\ensuremath{\times}$ (Public - Private)"  
local lbl_6 ""	
local lbl_7 "High $\ensuremath{\times}$ Private"	
local lbl_8 ""		
local lbl_9 "High $\ensuremath{\times}$ Public"
local lbl_10 ""
local lbl_11 "Low $\ensuremath{\times}$ Public"	
local lbl_12 ""
local lbl_13 "Observations"	
local lbl_14 "R-squared"	
local lbl_15 "Mean Dep. Var."
local lbl_16 "Mean Dep. Var. for Low $\ensuremath{\times}$ Private"
local lbl_17 "p-value High $\ensuremath{\times}$ Private - High $\ensuremath{\times}$ Public"	
local lbl_18 "p-value High $\ensuremath{\times}$ Private - Low $\ensuremath{\times}$ Public"		

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/TableA7.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3) & (4)  \\\\
tex  \\ [-1.5ex]
tex  & `outcome_1' & `outcome_2'  & `outcome_3' & `outcome_4'     \\\\
tex  \hline \\ 
forvalue t = 1/6 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t''  & `C3R`t''   & `C4R`t''   \\
}
tex  \hdashline \\ [-1.5ex]
tex \multicolumn{4}{l}{\underline{Regression Coefficients}} \\\\
forvalue t = 7/12 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t''  & `C3R`t''  & `C4R`t''   \\
}
tex  \\
forvalue t = 13/18 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t''  & `C3R`t''  & `C4R`t''    \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE A8: TAKE-UP AND USAGE, BY PRODUCT
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5 svar1-svar3

local k = 0

** NOTE: THE ORIGINAL CODE INCLUDES THE FOLLOWING:
** foreach y of varlist EL_simakmur ADamount_ihs_simakmur ADbalance_ihs_simakmur EL_ecash ADamount_ihs_ecash ADbalance_ihs_ecash {

** THIS HAS BEEN MODIFIED TO EXCLUDE VARIABLES COMING FROM THE ADMINISTRATIVE DATASET, WHICH CAN'T BE PUBLICLY SHARED.
foreach y of varlist EL_simakmur EL_ecash  {
	
	local k = `k' + 1
	local outcome_`k' : var label `y'
	
	* MODEL
	reg `y' high_private high_public low_public `controls', cl(agn_cl) 

	* MAIN ESTIMATES
	local v = 0
	
	foreach t in "high_private" "high_public-low_public" "high_public-low_public-high_private" {
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b':  di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s':  di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* REGRESSION COEFFICIENTS
	foreach t in high_private high_public low_public {
		local v = `v'+1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b':  di %12.3fc _b[`t']
		/*se*/ 		local C`k'R`s':  di %12.3fc _se[`t']
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(_b[`t']/_se[`t'])))
	}

	* OBSERVATIONS
	local C`k'R13:  di e(N)

	* R2
	local C`k'R14:   di %12.3fc e(r2)

	* MEAN DEP VARIABLE
	sum `y' 
	local C`k'R15:  di %12.3fc r(mean)

	* MEAN DEP VARIABLE FOR LOW PRIVATE
	sum `y' if low_private == 1
	local C`k'R16:  di %12.3fc r(mean)

	* T-TEST HIGH PRIVATE - HIGH PUBLIC
	test high_private = high_public 
	local C`k'R17:  di %12.3fc r(p)

	* T-TEST HIGH PRIVATE - LOW PUBLIC
	test high_private = low_public 
	local C`k'R18:  di %12.3fc r(p)

	*------------------------ FORMATTING
	* FORMAT SE ()
	foreach j of numlist 2 4 6 8 10 12 {
		local C`k'R`j': di trim("`C`k'R`j''")
		local C`k'R`j' = "(`C`k'R`j'')"
	}
			
	* ADD STARS IF CORRESPONDS
	foreach j of numlist 1 3 5 7 9 11 {
		if `pv`k'R`j'' <= 0.10 & `pv`k'R`j'' > 0.05 {
			local C`k'R`j' = "$`C`k'R`j''^{*}$"
		}
		else if `pv`k'R`j'' <= 0.05 & `pv`k'R`j'' > 0.01 {
			local C`k'R`j' = "$`C`k'R`j''^{**}$"
		}
		else if `pv`k'R`j'' <= 0.01 { 
			local C`k'R`j' = "$`C`k'R`j''^{***}$"
		}
	}

}

*------------------------ ROW TITLES
local lbl_1 "(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 ""	
local lbl_3 "(High - Low) $\ensuremath{\times}$ Public"
local lbl_4 "" 
local lbl_5 "(High - Low) $\ensuremath{\times}$ (Public - Private)"  
local lbl_6 ""	
local lbl_7 "High $\ensuremath{\times}$ Private"	
local lbl_8 ""		
local lbl_9 "High $\ensuremath{\times}$ Public"
local lbl_10 ""
local lbl_11 "Low $\ensuremath{\times}$ Public"	
local lbl_12 ""
local lbl_13 "Observations"	
local lbl_14 "R-squared"	
local lbl_15 "Mean Dep. Var."
local lbl_16 "Mean Dep. Var. for Low $\ensuremath{\times}$ Private"
local lbl_17 "p-value High $\ensuremath{\times}$ Private - High $\ensuremath{\times}$ Public"	
local lbl_18 "p-value High $\ensuremath{\times}$ Private - Low $\ensuremath{\times}$ Public"		

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/TableA8.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3) & & (4)  & (5) & (6)  \\\\
tex  \\ [-1.5ex]
tex \centering{Product:}  & \multicolumn{3}{c}{Savings Account} & & \multicolumn{3}{c}{Mobile Wallet} \\
tex \cline{2-4} \cline{6-8} 
tex  \\ [-1.5ex]
tex  & `outcome_1' & `outcome_2' & `outcome_3' & & `outcome_4' & `outcome_5' & `outcome_6'  \\\\
tex  \hline \\ 
forvalue t = 1/6 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t'' & & `C4R`t'' &  `C5R`t''  & `C6R`t''  \\
}
tex  \hdashline \\ [-1.5ex]
tex \multicolumn{4}{l}{\underline{Regression Coefficients}} \\\\
forvalue t = 7/12 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t'' & & `C4R`t'' &  `C5R`t''  & `C6R`t''  \\
}
tex  \\
forvalue t = 13/18 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t'' & & `C4R`t'' &  `C5R`t''  & `C6R`t''  \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE A9: AGENT TASKS
* ==============================================================================

use "$OUT/master_admin_final.dta", clear 

* DATA AT THE HOUSEHOLD LEVEL
duplicates drop agn_cl, force

label var ELagn_hrs_BMjob_any 				"Any Activity" 
label var ELagn_hrs_promotingshop_any 		"Promoting at Shop" 
label var ELagn_hrs_promotingoutshop_any 	"Promoting Outside Shop" 
label var ELagn_hrs_transact_any 			"Supporting with Client Sign-ups" 
label var ELagn_hrs_internet_any 			"Dealing with Client Complaints" 
label var ELagn_hrs_cash_any 				"Providing Cash for Client's transaction"
label var ELagn_hrs_educ_any 				"Assisting Clients with Product Usage" 

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5 svar1-svar3

local k = 0

foreach y of varlist ELagn_hrs_promotingshop_any ELagn_hrs_promotingoutshop_any ///
					 ELagn_hrs_transact_any ELagn_hrs_internet_any ELagn_hrs_cash_any ///
					 ELagn_hrs_educ_any ELagn_hrs_BMjob_any {
	
	replace `y' = 0 if `y' == .
	
	local k = `k' + 1
	
	local outcome_`k' :var label `y'
	
	* MODEL
	reg `y' high_private high_public low_public `controls', cl(agn_cl) 

	* MAIN ESTIMATES
	local v = 0
	
	foreach t in "high_private" "high_public-low_public" "high_public-low_public-high_private" {
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b':  di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s':  di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* REGRESSION COEFFICIENTS
	foreach t in high_private high_public low_public {
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b' : di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s' : di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* OBSERVATIONS
	local C`k'R13:  di e(N)

	* R2
	local C`k'R14:  di %12.3fc e(r2)

	* MEAN DEP VARIABLE
	sum `y' 
	local C`k'R15:  di %12.3fc r(mean)

	* MEAN DEP VARIABLE FOR LOW PRIVATE
	sum `y' if low_private==1
	local C`k'R16:  di %12.3fc r(mean)

	* T-TEST HIGH PRIVATE - HIGH PUBLIC
	test high_private = high_public 
	local C`k'R17:  di %12.3fc r(p)

	* T-TEST HIGH PRIVATE - LOW PUBLIC
	test high_private = low_public 
	local C`k'R18:  di %12.3fc r(p)

	*------------------------ FORMATTING
	* FORMAT SE ()
	foreach j of numlist 2 4 6 8 10 12 {
		local C`k'R`j': di trim("`C`k'R`j''")
		local C`k'R`j' = "(`C`k'R`j'')"
	}
			
	* ADD STARS IF CORRESPONDS
	foreach j of numlist 1 3 5 7 9 11 {

		if `pv`k'R`j'' <= 0.10 & `pv`k'R`j'' > 0.05 {
			local C`k'R`j' = "$`C`k'R`j''^{*}$"
		}
		else if `pv`k'R`j'' <= 0.05 & `pv`k'R`j'' > 0.01 {
			local C`k'R`j' = "$`C`k'R`j''^{**}$"
		}
		else if `pv`k'R`j'' <= 0.01 { 
			local C`k'R`j' = "$`C`k'R`j''^{***}$"
		}
	}

}

*------------------------ ROW TITLES
local lbl_1 "(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 ""	
local lbl_3 "(High - Low) $\ensuremath{\times}$ Public"
local lbl_4 "" 
local lbl_5 "(High - Low) $\ensuremath{\times}$ (Public - Private)"  
local lbl_6 ""	
local lbl_7 "High $\ensuremath{\times}$ Private"	
local lbl_8 ""		
local lbl_9 "High $\ensuremath{\times}$ Public"
local lbl_10 ""
local lbl_11 "Low $\ensuremath{\times}$ Public"	
local lbl_12 ""
local lbl_13 "Observations"	
local lbl_14 "R-squared"	
local lbl_15 "Mean Dep. Var."
local lbl_16 "Mean Dep. Var. for Low $\ensuremath{\times}$ Private"
local lbl_17 "p-value High $\ensuremath{\times}$ Private - High $\ensuremath{\times}$ Public"	
local lbl_18 "p-value High $\ensuremath{\times}$ Private - Low $\ensuremath{\times}$ Public"		

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/TableA9.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\\\
tex  \\ [-1.5ex]
tex {} & \multicolumn{6}{c}{Involved in Following Activity:} \\
tex \\
tex \cline{2-8}
tex \\
tex  & `outcome_1'  & `outcome_2' & `outcome_3' & `outcome_4'  & `outcome_5' & `outcome_6' & `outcome_7' \\\\
tex  \hline \\ 
forvalue t = 1/6 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t'' & `C5R`t''  & `C6R`t'' & `C7R`t'' \\
}
tex  \hdashline \\ [-1.5ex]
tex \multicolumn{4}{l}{\underline{Regression Coefficients}} \\\\
forvalue t = 7/12 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t'' & `C5R`t''  & `C6R`t'' & `C7R`t''  \\
}
tex  \\
forvalue t = 13/18 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t'' & `C5R`t''  & `C6R`t'' & `C7R`t'' \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE A10: AGENT INVESTMENTS
* ==============================================================================

use "$OUT/master_admin_final.dta", clear 

* DATA AT THE HOUSEHOLD LEVEL
duplicates drop agn_cl, force

label var ELagn_invest_computer 		"Bought/Upgraded Computers"
label var ELagn_invest_banner 			"Made Banners/Leaflets"
label var ELagn_invest_hired 			"Hired an Extra Employee"
label var ELagn_invest_compinternet 	"Bought a New Device with Better Internet Signal"
label var ELagn_invest_dataplan 		"Bought Data Plan"
label var ELagn_invest_any 				"Other"

local controls dcode1-dcode5 svar1-svar3

local k = 0
foreach y of varlist ELagn_invest_computer ELagn_invest_compinternet ///
					 ELagn_invest_dataplan ELagn_invest_banner ///
					 ELagn_invest_hired ELagn_invest_any {
	
	replace `y' = 0 if `y' == .
	
	local k = `k' + 1
	
	local outcome_`k' :var label `y'
	
	* MODEL
	reg `y' high_private high_public low_public `controls', cl(agn_cl) 

	* MAIN ESTIMATES
	local v = 0

	foreach t in "high_private" "high_public-low_public" "high_public-low_public-high_private" {
	
		local v = `v' + 1
		local b = 2*`v' - 1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b' : di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s' : di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	
	}

	* REGRESSION COEFFICIENTS
	foreach t in high_private high_public low_public {

		local v = `v' + 1
		local b = 2*`v' - 1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b' : di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s' : di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	
	}

	* OBSERVATIONS
	local C`k'R13:  di e(N)

	* R2
	local C`k'R14:   di %12.3fc e(r2)

	* MEAN DEP VARIABLE
	sum `y' 
	local C`k'R15:  di %12.3fc r(mean)

	* MEAN DEP VARIABLE FOR LOW PRIVATE
	sum `y' if low_private == 1
	local C`k'R16:  di %12.3fc r(mean)

	* T-TEST HIGH PRIVATE - HIGH PUBLIC
	test high_private = high_public 
	local C`k'R17:  di %12.3fc r(p)

	* T-TEST HIGH PRIVATE - LOW PUBLIC
	test high_private = low_public 
	local C`k'R18:  di %12.3fc r(p)

	*------------------------ FORMATTING
	* FORMAT SE ()
	foreach j of numlist 2 4 6 8 10 12 {
		local C`k'R`j': di trim("`C`k'R`j''")
		local C`k'R`j' = "(`C`k'R`j'')"
	}
			
	* ADD STARS IF CORRESPONDS	
	foreach j of numlist 1 3 5 7 9 11 {
		if `pv`k'R`j'' <= 0.10 & `pv`k'R`j'' > 0.05 {
			local C`k'R`j' = "$`C`k'R`j''^{*}$"
		}
		else if `pv`k'R`j'' <= 0.05 & `pv`k'R`j'' > 0.01 {
			local C`k'R`j' = "$`C`k'R`j''^{**}$"
		}
		else if `pv`k'R`j'' <= 0.01 { 
			local C`k'R`j' = "$`C`k'R`j''^{***}$"
		}
	}

}

*------------------------ ROW TITLES
local lbl_1 "(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 ""	
local lbl_3 "(High - Low) $\ensuremath{\times}$ Public"
local lbl_4 "" 
local lbl_5 "(High - Low) $\ensuremath{\times}$ (Public - Private)"  
local lbl_6 ""	
local lbl_7 "High $\ensuremath{\times}$ Private"	
local lbl_8 ""		
local lbl_9 "High $\ensuremath{\times}$ Public"
local lbl_10 ""
local lbl_11 "Low $\ensuremath{\times}$ Public"	
local lbl_12 ""
local lbl_13 "Observations"	
local lbl_14 "R-squared"	
local lbl_15 "Mean Dep. Var."
local lbl_16 "Mean Dep. Var. for Low $\ensuremath{\times}$ Private"
local lbl_17 "p-value High $\ensuremath{\times}$ Private - High $\ensuremath{\times}$ Public"	
local lbl_18 "p-value High $\ensuremath{\times}$ Private - Low $\ensuremath{\times}$ Public"		

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/TableA10.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3) & (4) & (5) & (6) \\\\
tex  \\ [-1.5ex]
tex {} & \multicolumn{6}{c}{Invested in:} \\
tex  \\
tex \cline{2-7}
tex \\
tex  & `outcome_1'  & `outcome_2' & `outcome_3' & `outcome_4'  & `outcome_5' & `outcome_6'  \\\\
tex  \hline \\ 
forvalue t = 1/6 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t'' & `C5R`t''  & `C6R`t'' \\
}
tex  \hdashline \\ [-1.5ex]
tex \multicolumn{4}{l}{\underline{Regression Coefficients}} \\\\
forvalue t = 7/12 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t'' & `C5R`t''  & `C6R`t''   \\
}
tex  \\
forvalue t = 13/18 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t'' & `C5R`t''  & `C6R`t'' \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE A11: AGENT HOUSEHOLD TARGETING
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

local h = 0
foreach x of varlist rich_hh finlit {

	cap gen high_public_`x'		= high_public*`x'
	cap gen high_private_`x'	= high_private*`x'
	cap gen low_public_`x'		= low_public*`x'
	cap gen low_private_`x'		= low_private*`x'

	local h = `h' + 1

	if `h' == 1 {
		local PanelA`h' "Wealthy Households"
		local PanelB`h' "Non-Wealthy Households"
	}
	if `h' == 2 {
		local PanelA`h' "Financially Literate Households"
		local PanelB`h' "Financially Illiterate Hoseholds"
	}

	local k = 0
	
	foreach y of varlist EL_takeupBM EL_pcaEffort EL_pcaStyle {
	
		*EL_takeupBM
		local k = `k' + 1
		local outcome_`k'`h' :var label `y'
		
		* MODEL
		reg `y' `x' high_public low_public high_private  high_public_`x' low_public_`x' high_private_`x' dcode*##`x' svar*##`x', noconstant cl(agn_cl) 
		matrix A = e(b)
		matrix V = e(V)

		* MAIN ESTIMATES
		local v = 0
		* Panel A and B respectively
		foreach t in "high_private + high_private_`x'" "(high_public-low_public) + (high_public_`x' - low_public_`x')" "(high_public-low_public-high_private) + (high_public_`x'-low_public_`x'-high_private_`x')" "high_private" "high_public-low_public" "high_public-low_public-high_private" { 
			local v = `v' + 1
			local b = 2*`v' - 1
			local s = 2*`v'
			lincom `t'
			/*beta*/    local C`k'R`b'`h':  di %12.3fc r(estimate)
			/*se*/ 		local C`k'R`s'`h':  di %12.3fc r(se)
			/*pv*/ 		local pv`k'R`b'`h': di 2*(1-normal(abs(r(estimate)/r(se))))
		}

		* OBSERVATIONS
		local C`k'R13`h':  di e(N)

		* P-VALUE PANEL A (HIGH - LOW) X PRIVATE= PANEL B (HIGH - LOW) X PRIVATE
		test high_private+high_private_`x'= high_private
		local C`k'R18`h':  di %12.3fc r(p)

		* P-VALUE PANEL A (HIGH - LOW) X PUBLIC= PANEL B (HIGH - LOW) X PUBLIC
		test (high_public-low_public) + (high_public_`x' - low_public_`x')= high_public-low_public
		local C`k'R19`h':  di %12.3fc r(p)

		* P-VALUE PANEL A (HIGH - LOW) X (PUBLIC - PRIVATE) = PANEL B (HIGH - LOW) X (PUBLIC - PRIVATE)
		test (high_public-low_public-high_private) + (high_public_`x'-low_public_`x'-high_private_`x')= high_public-low_public-high_private
		local C`k'R20`h':  di %12.3fc r(p)

		* R2
		local C`k'R15`h':   di %12.3fc e(r2)

		* % OBSERVATIONS IN PANEL A
		reg `y' `x' high_public low_private high_private high_public_`x' low_private_`x' high_private_`x' dcode*##`x' svar*##`x' if `x'==1, noconstant cl(agn_cl) 
		/*% obs*/   local C`k'R14`h':  di %12.2fc e(N)/`C`k'R13`h''*100

		* MEAN DEP VARIABLE FULL SAMPLE
		sum `y'
		local mean = r(mean)
		local C`k'R16`h':  di %12.3fc r(mean)

		* MEAN DEP VARIABLE LOW PRIVATE FULL SAMPLE
		sum `y' if low_private == 1
		local C`k'R17`h':  di %12.3fc r(mean)

		*------------------------ FORMATTING
		* FORMAT SE ()
		foreach j of numlist 2 4 6 8 10 12 {
			local C`k'R`j'`h': di trim("`C`k'R`j'`h''")
			local C`k'R`j'`h' = "(`C`k'R`j'`h'')"
		}
		
		* ADD STARS IF CORRESPONDS
		foreach j of numlist 1 3 5 7 9 11 {
			if `pv`k'R`j'`h'' <= 0.10 & `pv`k'R`j'`h'' > 0.05 {
				local C`k'R`j'`h' = "$`C`k'R`j'`h''^{*}$"
			}
			else if `pv`k'R`j'`h'' <= 0.05 & `pv`k'R`j'`h'' > 0.01 {
				local C`k'R`j'`h' = "$`C`k'R`j'`h''^{**}$"
			}
			else if `pv`k'R`j'`h'' <=0.01 { 
				local C`k'R`j'`h' = "$`C`k'R`j'`h''^{***}$"
			}
		}

	}		

}

*------------------------ ROW TITLES
local lbl_1 "(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 ""	
local lbl_3 "(High - Low) $\ensuremath{\times}$ Public"
local lbl_4 "" 
local lbl_5 "(High - Low) $\ensuremath{\times}$ (Public - Private)" 
local lbl_6 ""
local lbl_7 "(High - Low) $\ensuremath{\times}$ Private"  
local lbl_8 ""	
local lbl_9 "(High - Low) $\ensuremath{\times}$ Public"
local lbl_10 "" 
local lbl_11 "(High - Low) $\ensuremath{\times}$ (Public - Private)" 
local lbl_12 ""
local lbl_13 "Observations"	
local lbl_14 "\% Observations in Panel A"	
local lbl_15 "R-squared"	
local lbl_16 "Mean Dep. Var."
local lbl_17 "Mean Dep. Var. for Low $\ensuremath{\times}$ Private"
local lbl_18 "p-value [(High - Low) x Private] Panel A = Panel B"	
local lbl_19 "p-value [(High - Low) x Public] Panel A = Panel B"	
local lbl_20 "p-value [(High - Low) x (Public - Private)] Panel A = Panel B"	

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/TableA11.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) &  (2) & (3) & & (4) &  (5) & (6) \\\\
tex  \\ [-1.5ex]
tex  & `outcome_11' &  `outcome_21' & `outcome_31' & & `outcome_12' &  `outcome_22' & `outcome_32' \\\\
tex  \hline \\ 
tex \multicolumn{1}{l}{\textbf{Panel A Sample:}} & &\multicolumn{1}{c}{`PanelA1'} & & & &\multicolumn{1}{c}{`PanelA2'} \\\\
forvalue t = 1/6 {
tex `lbl_`t''  & `C1R`t'1' & `C2R`t'1' & `C3R`t'1' & & `C1R`t'2' & `C2R`t'2' & `C3R`t'2'  \\
}
tex  \\
tex \multicolumn{1}{l}{\textbf{Panel B Sample:}} & & \multicolumn{1}{c}{`PanelB1'} & & & & \multicolumn{1}{c}{`PanelB2'} \\\\
forvalue t = 7/12 {
tex `lbl_`t''  & `C1R`t'1' & `C2R`t'1' & `C3R`t'1' & & `C1R`t'2' & `C2R`t'2' & `C3R`t'2'   \\
}
tex  \\
forvalue t = 13/20 {
tex `lbl_`t''  & `C1R`t'1' & `C2R`t'1' & `C3R`t'1' & & `C1R`t'2' & `C2R`t'2' & `C3R`t'2'   \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE A12: PERCEPTIONS OF POTENTIAL CLIENTS – INDIVIDUAL VARIABLES
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

label var know_any 						"Agent Pay is Commission-Based"
label var EL_reliable_product 			"Products are Reliable"
label var EL_fees_BM 					"Fees are Reasonable"
label var EL_money_safe 				"Money is Safe"
label var EL_safe_product 				"Product is Safe"
label var EL_confidence_BM 				"Confidence in the Bank"
label var EL_trust_banks_village 		"Trust Banks in the Village"		
label var EL_confidence_state_banks 	"Contracts with Bank are Enforced"			
label var EL_trust_agent 				"Trust Agent"
label var EL_competent_agent 			"Agent is Competent"
label var EL_altruism_agent 			"Agent is Altruistic"	
label var EL_wallet_agent				"Agent Would not Steal Wallet"

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5 svar1-svar3

local k = 0
foreach y of varlist know_any EL_reliable_product EL_fees_BM EL_money_safe EL_safe_product ///
					 EL_confidence_BM EL_trust_banks_village EL_confidence_state_banks ///
					 EL_trust_agent EL_competent_agent EL_altruism_agent EL_wallet_agent {

	local k = `k' + 1
	
	local outcome_`k' :var label `y'

	* MODEL
	reg `y' high_private high_public low_public `controls', cl(agn_cl) 

	* MAIN ESTIMATES
	local v = 0
	
	foreach t in "high_private" "high_public-low_public" "high_public-low_public-high_private" {
		local v = `v' + 1
		local b = 2*`v' - 1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b' : di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s' : di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* REGRESSION COEFFICIENTS
	foreach t in high_private high_public low_public {
		local v = `v' + 1
		local b = 2*`v' - 1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b' : di %12.3fc _b[`t']
		/*se*/ 		local C`k'R`s' : di %12.3fc _se[`t']
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(_b[`t']/_se[`t'])))
	}

	* OBSERVATIONS
	local C`k'R13:  di e(N)

	* R2
	local C`k'R14:  di %12.3fc e(r2)

	* MEAN DEP VARIABLE
	sum `y' 
	local C`k'R15:  di %12.3fc r(mean)

	* MEAN DEP VARIABLE FOR LOW PRIVATE
	sum `y' if low_private==1
	local C`k'R16:  di %12.3fc r(mean)

	* T-TEST HIGH PRIVATE - HIGH PUBLIC
	test high_private = high_public 
	local C`k'R17:  di %12.3fc r(p)

	* T-TEST HIGH PRIVATE - LOW PUBLIC
	test high_private = low_public 
	local C`k'R18:  di %12.3fc r(p)

	*------------------------ FORMATTING
	* FORMAT SE ()
	foreach j of numlist 2 4 6 8 10 12 {
		local C`k'R`j': di trim("`C`k'R`j''")
		local C`k'R`j' = "(`C`k'R`j'')"
	}
			
	* ADD STARS IF CORRESPONDS
	foreach j of numlist 1 3 5 7 9 11 {
		if `pv`k'R`j'' <= 0.10 & `pv`k'R`j'' > 0.05 {
			local C`k'R`j' = "$`C`k'R`j''^{*}$"
		}
		else if `pv`k'R`j'' <= 0.05 & `pv`k'R`j'' > 0.01 {
			local C`k'R`j'="$`C`k'R`j''^{**}$"
		}
		else if `pv`k'R`j'' <= 0.01 { 
			local C`k'R`j' = "$`C`k'R`j''^{***}$"
		}
	}

}

*------------------------ ROW TITLES
local lbl_1 "(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 ""	
local lbl_3 "(High - Low) $\ensuremath{\times}$ Public"
local lbl_4 "" 
local lbl_5 "(High - Low) $\ensuremath{\times}$ (Public - Private)"  
local lbl_6 ""	
local lbl_7 "High $\ensuremath{\times}$ Private"	
local lbl_8 ""		
local lbl_9 "High $\ensuremath{\times}$ Public"
local lbl_10 ""
local lbl_11 "Low $\ensuremath{\times}$ Public"	
local lbl_12 ""
local lbl_13 "Observations"	
local lbl_14 "R-squared"	
local lbl_15 "Mean Dep. Var."
local lbl_16 "Mean Dep. Var. for Low $\ensuremath{\times}$ Private"
local lbl_17 "p-value High $\ensuremath{\times}$ Private - High $\ensuremath{\times}$ Public"	
local lbl_18 "p-value High $\ensuremath{\times}$ Private - Low $\ensuremath{\times}$ Public"		

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/TableA12.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3)  & (4) & (5) & & (6) & (7) & (8) & &  (9) & (10) & (11) & (12)  \\\\
tex & \multicolumn{5}{c}{Product} & & \multicolumn{3}{c}{Bank}  & &  \multicolumn{4}{c}{Agent}  \\
tex  \cline{2-6} \cline{8-10} \cline{12-15}
tex  \\ [-1.5ex]
tex & `outcome_1' & `outcome_2' & `outcome_3'  & `outcome_4' &  `outcome_5' & & `outcome_6' & `outcome_7' &  `outcome_8' & & `outcome_9' & `outcome_10' & `outcome_11' & `outcome_12' \\\\
tex  \hline \\ 
forvalue t = 1/6 {
tex `lbl_`t'' & `C1R`t''  & `C2R`t'' & `C3R`t'' & `C4R`t'' & `C5R`t'' & &  `C6R`t'' & `C7R`t'' &  `C8R`t'' & &  `C9R`t'' & `C10R`t'' &   `C11R`t'' &   `C12R`t''    \\
}
tex  \hdashline \\ [-1.5ex]
tex \multicolumn{13}{l}{\underline{Regression Coefficients}} \\\\
forvalue t = 7/12 {
tex `lbl_`t'' & `C1R`t''  & `C2R`t'' & `C3R`t'' & `C4R`t'' &  `C5R`t'' &  & `C6R`t'' & `C7R`t'' &  `C8R`t'' & &  `C9R`t'' & `C10R`t'' &   `C11R`t'' &   `C12R`t''    \\
}
tex  \\
forvalue t = 13/18 {
tex `lbl_`t'' & `C1R`t''  & `C2R`t'' & `C3R`t'' & `C4R`t'' & `C5R`t'' &  & `C6R`t'' &  `C7R`t'' &  `C8R`t'' &  & `C9R`t'' & `C10R`t'' &   `C11R`t'' &   `C12R`t''    \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE A13: HETEROGENEOUS EFFECTS ON PERCEPTIONS OF POTENTIAL CLIENTS AND AGENT 
*		     EFFORT BY TRUST AND KNOWLEDGE
* ==============================================================================

use "$OUT/master_admin_final.dta", clear

local h = 0

foreach x of varlist BLclose_agn BLtrust_AGNadvice BLknow_mobile_bk {

	cap gen high_public_`x' 	= high_public*`x'
	cap gen high_private_`x' 	= high_private*`x'
	cap gen low_public_`x'		= low_public*`x'
	cap gen low_private_`x'		= low_private*`x'

	local h = `h' + 1

	if `h' == 1 {
		local PanelA`h' "Friends or Family of the Agent"
		local PanelB`h' "Not Friends or Family of the Agent"
	}
	if `h' == 2 {
		local PanelA`h' "Trust the Agent's Financial Advices"
		local PanelB`h' "Do Not Trust the Agent's Financial Advices"
	}
	if `h' == 3 {
		local PanelA`h' "Know Branchless Banking"
		local PanelB`h' "Do Not Know Branchless Banking"
	}

	local k = 0
	
	foreach y of varlist EL_pcaAll EL_pcaEffort EL_pcaStyle {
		
		local k = `k' + 1
		local outcome_`k'`h' : var label `y'
		
		* MODEL
		reg `y' `x' high_public low_public high_private high_public_`x' low_public_`x' high_private_`x' dcode*##`x' svar*##`x', noconstant cl(agn_cl) 

		local v = 0
		
		foreach t in "high_private+high_private_`x'" "high_public-low_public+high_public_`x'-low_public_`x'" ///
		 "high_public-low_public+high_public_`x'-low_public_`x'-(high_private+high_private_`x')" /*Panel A*/ /// 
		"high_private" "high_public-low_public" "high_public-low_public-high_private" /*Panel B*/ {
			
			local v=`v'+1
			local b=2*`v'-1
			local s=2*`v'
			lincom `t'
			/*beta*/    local C`k'R`b'`h' :  di %12.3fc r(estimate)
			/*se*/ 		local C`k'R`s'`h' :  di %12.3fc r(se)
			/*pv*/ 		local pv`k'R`b'`h':  di 2*(1-normal(abs(r(estimate)/r(se))))
		
		}

		* P-VALUE PANEL A=PANEL B
		test  high_public-low_public+high_public_`x'-low_public_`x'-(high_private+high_private_`x') = high_public-low_public-high_private
		local C`k'R18`h':  di %12.3fc r(p)

		* OBSERVATIONS
		local C`k'R13`h':  di e(N)

		* R2
		local C`k'R15`h':   di %12.3fc e(r2)

		* % OBSERVATIONS IN PANEL A
		reg `y' `x' high_public low_private high_private high_public_`x' low_private_`x' high_private_`x' dcode*##`x' svar*##`x' if `x'==1, noconstant cl(agn_cl) 
		local C`k'R14`h':  di %12.2fc e(N)/`C`k'R13`h''*100


		* MEAN DEP VARIABLE IN FULL SAMPLE
		sum `y'
		local mean = r(mean)
		local C`k'R16`h':  di %12.3fc `mean'

		* MEAN DEP VARIABLE FOR FULL SAMPLE
		sum `y' if low_private == 1 
		local C`k'R17`h':  di %12.3fc r(mean)

		* FORMAT SE ()
		foreach j of numlist 2 4 6 8 10 12 {
			local C`k'R`j'`h': di trim("`C`k'R`j'`h''")
			local C`k'R`j'`h' = "(`C`k'R`j'`h'')"
		}
				
		* ADD STARS IF CORRESPONDS
		foreach j of numlist 1 3 5 7 9 11 {
			if `pv`k'R`j'`h'' <= 0.10 & `pv`k'R`j'`h'' > 0.05 {
				local C`k'R`j'`h' = "$`C`k'R`j'`h''^{*}$"
			}
			else if `pv`k'R`j'`h'' <= 0.05 & `pv`k'R`j'`h'' > 0.01 {
				local C`k'R`j'`h'="$`C`k'R`j'`h''^{**}$"
			}
			else if `pv`k'R`j'`h'' <= 0.01 { 
				local C`k'R`j'`h' = "$`C`k'R`j'`h''^{***}$"
			}
		}
	}

}

* ROW TITLES
local lbl_1 	"(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 	""
local lbl_3 	"(High - Low) $\ensuremath{\times}$ Public" 
local lbl_4 	""
local lbl_5 	"(High - Low) $\ensuremath{\times}$ (Public - Private)"  
local lbl_6 	""	
local lbl_7 	"(High - Low) $\ensuremath{\times}$ Private"  
local lbl_8 	""	
local lbl_9 	"(High - Low) $\ensuremath{\times}$ Public" 
local lbl_10 	""
local lbl_11 	"(High - Low) $\ensuremath{\times}$ (Public - Private)"  
local lbl_12 	""		
local lbl_13 	"Observations"	
local lbl_14 	"\% Observations in Panel A"	
local lbl_15 	"R-squared"	
local lbl_16 	"Mean Dep. Var."
local lbl_17 	"Mean Dep. Var. for Low $\ensuremath{\times}$ Private"
local lbl_18 	"p-value Panel A=Panel B"	

*------------------------ CREATE LATEX OUTPUT FILE		
texdoc init "$TEX/TableA13.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) &  (2) & (3) & & (4) & (5) & (6) & & (7) & (8) & (9)    \\\\
tex  \\ [-1.5ex]
tex  & `outcome_11' & `outcome_21' & `outcome_31' & & `outcome_11' & `outcome_21' & `outcome_31' & & `outcome_11' & `outcome_21' & `outcome_31' \\\\
tex  \hline \\ 
tex \multicolumn{1}{l}{\textbf{Panel A Sample:}} & \multicolumn{3}{P{8.6cm}}{{`PanelA1'}} & & \multicolumn{3}{P{8.6cm}}{{`PanelA2'}} & & \multicolumn{3}{P{8.6cm}}{{`PanelA3'}}  \\\\
forvalue t = 5/6 {
tex `lbl_`t''  & `C1R`t'1' & `C2R`t'1' & `C3R`t'1' & & `C1R`t'2' & `C2R`t'2' & `C3R`t'2' & & `C1R`t'3' & `C2R`t'3' & `C3R`t'3'    \\
}
tex  \\ 
tex \multicolumn{1}{l}{\textbf{Panel B Sample:}} & \multicolumn{3}{P{8.6cm}}{{`PanelB1'}} & & \multicolumn{3}{P{8.6cm}}{{`PanelB2'}} &  & \multicolumn{3}{P{8.6cm}}{{`PanelB3'}}  \\\\
forvalue t = 11/12 {
tex `lbl_`t''  & `C1R`t'1' & `C2R`t'1' & `C3R`t'1' & & `C1R`t'2' & `C2R`t'2' & `C3R`t'2' & & `C1R`t'3' & `C2R`t'3' & `C3R`t'3'    \\
}
tex  \\
forvalue t = 13/18 {
tex `lbl_`t''  & `C1R`t'1' & `C2R`t'1' & `C3R`t'1' & & `C1R`t'2' & `C2R`t'2' & `C3R`t'2' & & `C1R`t'3' & `C2R`t'3' & `C3R`t'3'   \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*

* ==============================================================================
* TABLE A14: LONG-TERM EFFECTS ON TAKE-UP AND USAGE PER CLIENT
* ==============================================================================

**** NOTE: THIS TABLE USES ADMINISTRATIVE DATA WHICH CAN'T BE SHARED
**** WE COMMENT OUT THIS SECTION TO ALLOW THE CODE TO RUN SMOOTHLY

/*
use "$OUT/longterm_agentlevel_final.dta", clear

gen TU_rate = med_client/BLnbHH
	replace TU_rate = 0 if TU_rate == .
	label var TU_rate "Take-Up Rate"

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5  svar1-svar3

local k = 0

foreach y of varlist  med_freq_cl asinh_med_bal_cl asinh_med_sv_cl {	

	local label_`y' :var label `y'

	generate NEW_`y' = `y'/(frac_HHentrep + 0.3*(1-frac_HHentrep))
		label var NEW_`y' "`label_`y''"

	local k = `k' + 1
	
	local outcome_`k' :var label NEW_`y'
	
		replace NEW_`y' = 0 if NEW_`y' == .
	
	* MODEL
	reg NEW_`y' high_private high_public low_public   `controls',  cl(agn_cl) 

	* MAIN ESTIMATES
	local v=0
	foreach t in "high_private" "high_public-low_public" "high_public-low_public-high_private" {
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b':  di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s':  di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* REGRESSION COEFFICIENTS
	foreach t in high_private high_public low_public {
		local v = `v' + 1
		local b = 2*`v' - 1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b':  di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s':  di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* OBSERVATIONS
	local C`k'R13:  di e(N)

	* R2
	local C`k'R14:  di %12.3fc e(r2)

	* MEAN DEP VARIABLE
	sum NEW_`y' 
	local C`k'R15:  di %12.3fc r(mean)

	* MEAN DEP VARIABLE FOR LOW PRIVATE
	sum NEW_`y' if low_private==1
	local C`k'R16:  di %12.3fc r(mean)

	* T-TEST HIGH PRIVATE - HIGH PUBLIC
	test high_private = high_public 
	local C`k'R17:  di %12.3fc r(p)

	* T-TEST HIGH PRIVATE - LOW PUBLIC
	test high_private = low_public 
	local C`k'R18:  di %12.3fc r(p)

	* FORMAT SE ()
	foreach j of numlist 2 4 6 8 10 12 {
		local C`k'R`j': di trim("`C`k'R`j''")
		local C`k'R`j' = "(`C`k'R`j'')"
	}
			
	* ADD STARS IF CORRESPONDS
	foreach j of numlist 1 3 5 7 9 11 {
		if `pv`k'R`j'' <= 0.10 & `pv`k'R`j'' > 0.05 {
		local C`k'R`j' = "$`C`k'R`j''^{*}$"
		}
		else if `pv`k'R`j'' <= 0.05 & `pv`k'R`j'' > 0.01 {
		local C`k'R`j'="$`C`k'R`j''^{**}$"
		}
		else if `pv`k'R`j'' <= 0.01 { 
		local C`k'R`j'="$`C`k'R`j''^{***}$"
		}
	}

}

*------------------------ ROW TITLES
local lbl_1 "(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 ""	
local lbl_3 "(High - Low) $\ensuremath{\times}$ Public"
local lbl_4 "" 
local lbl_5 "(High - Low) $\ensuremath{\times}$ (Public - Private)"  
local lbl_6 ""	
local lbl_7 "High $\ensuremath{\times}$ Private"	
local lbl_8 ""		
local lbl_9 "High $\ensuremath{\times}$ Public"
local lbl_10 ""
local lbl_11 "Low $\ensuremath{\times}$ Public"	
local lbl_12 ""
local lbl_13 "Observations"	
local lbl_14 "R-squared"	
local lbl_15 "Mean Dep. Var."
local lbl_16 "Mean Dep. Var. for Low $\ensuremath{\times}$ Private"
local lbl_17 "p-value High $\ensuremath{\times}$ Private - High $\ensuremath{\times}$ Public"	
local lbl_18 "p-value High $\ensuremath{\times}$ Private - Low $\ensuremath{\times}$ Public"		

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/TableA14.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3) \\\\
tex  \\ [-1.5ex]
tex  & `outcome_1' & `outcome_2' & `outcome_3' \\\\
tex  \hline \\ 
forvalue t = 1/6 {
tex `lbl_`t'' & `C1R`t'' & `C2R`t'' & `C3R`t'' \\
}
tex  \hdashline \\ [-1.5ex]
tex \multicolumn{4}{l}{\underline{Regression Coefficients}} \\\\
forvalue t = 7/12 {
tex `lbl_`t'' & `C1R`t'' & `C2R`t'' & `C3R`t''  \\
}
tex  \\
forvalue t = 13/18 {
tex `lbl_`t'' & `C1R`t'' & `C2R`t'' & `C3R`t''  \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*
*/

* ==============================================================================
* TABLE A15: LONG-TERM EFFECTS, RE-SCALED UNDER DIFFERENT ASSUMPTIONS ABOUT 
*			 GAMMA
* ==============================================================================

**** NOTE: THIS TABLE USES ADMINISTRATIVE DATA WHICH CAN'T BE SHARED
**** WE COMMENT OUT THIS SECTION TO ALLOW THE CODE TO RUN SMOOTHLY

/*

* MERGE TO FINAL DATASET
use "$OUT/longterm_agentlevel_final.dta", clear

gen TU_rate = avg_client/BLnbHH
	replace TU_rate = 0 if TU_rate == .
	label var TU_rate "Take-Up Rate"

* COMPUTE THE SCALED DOWN NUMBER OF PEOPLE WHO TOOK UP
generate	TUREnt_1=TU_rate/(frac_HHentrep + 0*(1-frac_HHentrep))
generate	TUREnt_2=TU_rate/(frac_HHentrep + 0.1*(1-frac_HHentrep))
generate	TUREnt_3=TU_rate/(frac_HHentrep + 0.2*(1-frac_HHentrep))
generate	TUREnt_4=TU_rate/(frac_HHentrep + 0.3*(1-frac_HHentrep))
generate	TUREnt_5=TU_rate/(frac_HHentrep + 0.4*(1-frac_HHentrep))
generate	TUREnt_6=TU_rate/(frac_HHentrep + 0.5*(1-frac_HHentrep))
generate	TUREnt_7=TU_rate/(frac_HHentrep + 0.6*(1-frac_HHentrep))
generate	TUREnt_8=TU_rate/(frac_HHentrep + 0.7*(1-frac_HHentrep))
generate	TUREnt_9=TU_rate/(frac_HHentrep + 0.8*(1-frac_HHentrep))
generate	TUREnt_10=TU_rate/(frac_HHentrep + 0.9*(1-frac_HHentrep))
generate	TUREnt_11=TU_rate/(frac_HHentrep + 1*(1-frac_HHentrep))

label var TUREnt_6 "$\ensuremath{\gamma=0.5}$"
label var TUREnt_5 "$\ensuremath{\gamma=0.4}$"
label var TUREnt_4 "$\ensuremath{\gamma=0.3}$"
label var TUREnt_3 "$\ensuremath{\gamma=0.2}$"
label var TUREnt_2 "$\ensuremath{\gamma=0.1}$"

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5  svar1-svar3

local k = 0

foreach y of varlist TUREnt_6 TUREnt_5 TUREnt_4 TUREnt_3 TUREnt_2 {

	local k = `k' + 1
	
	local outcome_`k' : var label `y'

	* MODEL
	reg `y' high_private high_public low_public `controls', cl(agn_cl) 

	* MAIN ESTIMATES
	local v = 0
	
	foreach t in "high_private" "high_public-low_public" "high_public-low_public-high_private" {
		local v=`v'+1
		local b=2*`v'-1
		local s=2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b' : di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s' : di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* REGRESSION COEFFICIENTS
	foreach t in high_private high_public low_public {
		local v = `v' + 1
		local b = 2*`v' - 1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b' : di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s' : di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* OBSERVATIONS
	local C`k'R13:  di e(N)

	* R2
	local C`k'R14:  di %12.3fc e(r2)

	* MEAN DEP VARIABLE
	sum `y' 
	local C`k'R15:  di %12.3fc r(mean)

	* MEAN DEP VARIABLE FOR LOW PRIVATE
	sum `y' if low_private==1
	local C`k'R16:  di %12.3fc r(mean)

	* T-TEST HIGH PRIVATE - HIGH PUBLIC
	test high_private = high_public 
	local C`k'R17:  di %12.3fc r(p)

	* T-TEST HIGH PRIVATE - LOW PUBLIC
	test high_private = low_public 
	local C`k'R18:  di %12.3fc r(p)

	*------------------------ FORMATTING
	* FORMAT SE ()
	foreach j of numlist 2 4 6 8 10 12 {
		local C`k'R`j': di trim("`C`k'R`j''")
		local C`k'R`j' = "(`C`k'R`j'')"
	}
			
	* ADD STARS IF CORRESPONDS
	foreach j of numlist 1 3 5 7 9 11 {
		if `pv`k'R`j'' <= 0.10 & `pv`k'R`j'' > 0.05 {
			local C`k'R`j' = "$`C`k'R`j''^{*}$"
		}
		else if `pv`k'R`j'' <= 0.05 & `pv`k'R`j'' > 0.01 {
			local C`k'R`j' = "$`C`k'R`j''^{**}$"
		}
		else if `pv`k'R`j'' <= 0.01 { 
			local C`k'R`j' = "$`C`k'R`j''^{***}$"
		}
	}

}

*------------------------ ROW TITLES
local lbl_1 "(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 ""	
local lbl_3 "(High - Low) $\ensuremath{\times}$ Public"
local lbl_4 "" 
local lbl_5 "(High - Low) $\ensuremath{\times}$ (Public - Private)"  
local lbl_6 ""	
local lbl_7 "High $\ensuremath{\times}$ Private"	
local lbl_8 ""		
local lbl_9 "High $\ensuremath{\times}$ Public"
local lbl_10 ""
local lbl_11 "Low $\ensuremath{\times}$ Public"	
local lbl_12 ""
local lbl_13 "Observations"	
local lbl_14 "R-squared"	
local lbl_15 "Mean Dep. Var."
local lbl_16 "Mean Dep. Var. for Low $\ensuremath{\times}$ Private"
local lbl_17 "p-value High $\ensuremath{\times}$ Private - High $\ensuremath{\times}$ Public"	
local lbl_18 "p-value High $\ensuremath{\times}$ Private - Low $\ensuremath{\times}$ Public"		

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/TableA15.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3) & (4) & (5) \\\\
tex  \\ [-1.5ex]
tex  & `outcome_1'  & `outcome_2' & `outcome_3' & `outcome_4'  & `outcome_5'  \\\\
tex \\
tex  \hline \\ 
forvalue t = 1/6 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t'' & `C5R`t'' \\
}
tex  \hdashline \\ [-1.5ex]
tex \multicolumn{4}{l}{\underline{Regression Coefficients}} \\\\
forvalue t = 7/12 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t'' & `C5R`t'' \\
}
tex  \\
forvalue t = 13/18 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t'' & `C5R`t'' \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*
*/

* ==============================================================================
* TABLE A16: LONG-TERM EFFECTS ON TAKE-UP AND USAGE (NO RE-SCALING)
* ==============================================================================
**** NOTE: THIS TABLE USES ADMINISTRATIVE DATA WHICH CAN'T BE SHARED
**** WE COMMENT OUT THIS SECTION TO ALLOW THE CODE TO RUN SMOOTHLY

/*
use "$OUT/longterm_agentlevel_final.dta", clear

gen TU_rate = med_client/BLnbHH
	label var TU_rate "Take-Up Rate"

* SET CONTROLS TO ADD IN ALL REGRESSIONS (STRATIFIC. VARIABLES)
local controls dcode1-dcode5 svar1-svar3

local k = 0

foreach y in TU_rate med_freq med_freq_cl asinh_med_balance asinh_med_bal_cl asinh_med_sv asinh_med_sv_cl {
 
	local k = `k' + 1
	
	local outcome_`k': var label `y'
	
	replace `y' = 0 if `y' == .

	* MODEL
	reg `y' high_private high_public low_public `controls', cl(agn_cl) 

	* MAIN ESTIMATES
	local v = 0
	foreach t in "high_private" "high_public-low_public" "high_public-low_public-high_private" {
		local v = `v' + 1
		local b = 2*`v' - 1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b':  di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s':  di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* REGRESSION COEFFICIENTS
	foreach t in high_private high_public low_public {
		local v = `v' + 1
		local b = 2*`v'-1
		local s = 2*`v'
		lincom `t'
		/*beta*/    local C`k'R`b':  di %12.3fc r(estimate)
		/*se*/ 		local C`k'R`s':  di %12.3fc r(se)
		/*pv*/ 		local pv`k'R`b': di 2*(1-normal(abs(r(estimate)/r(se))))
	}

	* OBSERVATIONS
	local C`k'R13:  di e(N)

	* R2
	local C`k'R14:   di %12.3fc e(r2)

	* MEAN DEP VARIABLE
	sum `y' 
	local C`k'R15:  di %12.3fc r(mean)

	* MEAN DEP VARIABLE FOR LOW PRIVATE
	sum `y' if low_private == 1
	local C`k'R16:  di %12.3fc r(mean)

	* T-TEST HIGH PRIVATE - HIGH PUBLIC
	test high_private = high_public 
	local C`k'R17:  di %12.3fc r(p)

	* T-TEST HIGH PRIVATE - LOW PUBLIC
	test high_private = low_public 
	local C`k'R18:  di %12.3fc r(p)

	*------------------------ FORMATTING 
	* FORMAT SE ()
	foreach j of numlist 2 4 6 8 10 12 {
		local C`k'R`j': di trim("`C`k'R`j''")
		local C`k'R`j' = "(`C`k'R`j'')"
	}
			
	* ADD STARS IF CORRESPONDS
	foreach j of numlist 1 3 5 7 9 11 {
		if `pv`k'R`j'' <= 0.10 & `pv`k'R`j'' > 0.05 {
		local C`k'R`j' = "$`C`k'R`j''^{*}$"
		}
		else if `pv`k'R`j'' <= 0.05 & `pv`k'R`j'' > 0.01 {
		local C`k'R`j' = "$`C`k'R`j''^{**}$"
		}
		else if `pv`k'R`j'' <= 0.01 { 
		local C`k'R`j' = "$`C`k'R`j''^{***}$"
		}
	}

}

*------------------------ ROW TITLES
local lbl_1 "(High - Low) $\ensuremath{\times}$ Private"  
local lbl_2 ""	
local lbl_3 "(High - Low) $\ensuremath{\times}$ Public"
local lbl_4 "" 
local lbl_5 "(High - Low) $\ensuremath{\times}$ (Public - Private)"  
local lbl_6 ""	
local lbl_7 "High $\ensuremath{\times}$ Private"	
local lbl_8 ""		
local lbl_9 "High $\ensuremath{\times}$ Public"
local lbl_10 ""
local lbl_11 "Low $\ensuremath{\times}$ Public"	
local lbl_12 ""
local lbl_13 "Observations"	
local lbl_14 "R-squared"	
local lbl_15 "Mean Dep. Var."
local lbl_16 "Mean Dep. Var. for Low $\ensuremath{\times}$ Private"
local lbl_17 "p-value High $\ensuremath{\times}$ Private - High $\ensuremath{\times}$ Public"	
local lbl_18 "p-value High $\ensuremath{\times}$ Private - Low $\ensuremath{\times}$ Public"		

*------------------------ CREATE LATEX OUTPUT FILE
texdoc init "$TEX/TableA16.tex", replace force
tex  \\ [-1.5ex]
tex \hline\hline \\ [-1.5ex]
tex {} & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\\\
tex  \\ [-1.5ex]
tex  & `outcome_1'  & `outcome_2' & `outcome_3' & `outcome_4'  & `outcome_5'  & `outcome_6' & `outcome_7' \\\\
tex  \hline \\ 
forvalue t = 1/6 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t'' & `C5R`t''  & `C6R`t'' & `C7R`t'' \\
}
tex  \hdashline \\ [-1.5ex]
tex \multicolumn{4}{l}{\underline{Regression Coefficients}} \\\\
forvalue t = 7/12 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t'' & `C5R`t''  & `C6R`t'' & `C7R`t''  \\
}
tex  \\
forvalue t = 13/18 {
tex `lbl_`t''  & `C1R`t''  & `C2R`t'' & `C3R`t''  & `C4R`t'' & `C5R`t''  & `C6R`t'' & `C7R`t'' \\
}
tex  \hline\hline \\ [-1.5ex]
texdoc close

	* Drop macros
	macro drop _C* _lbl*
*/

log close
	
